npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pixel-starry/hook-store

v1.0.0

Published

A light data management tool for react framework.

Readme

HookStore

HookStore 是一个轻量级的 React 状态管理 hooks 库,支持精细化更新。

store 定义

现在我们来编写一个计数器 store

import { BaseStore } from '@pixel-starry/hook-store';

class CountStore extends BaseStore {
  count = 0;
  count2 = 0;

  add(num: number) {
    this.setState({ count: num });
  }

  reset() {
    this.setState({ count: 0 });
  }

  times(num: number) {
    this.setState({ count: this.count * num  });
  }
}

使用 store

import { StoreProvider, useStore } from '@pixel-starry/hook-store';
const Child = () => {
  const store = useStore(CountStore);
  return (
    <div>
      <div>{store.count}</div>
      <button onClick={() => store.add(1)}>加1</button>
      <button onClick={() => store.times(2)}>乘2</button>
      <button onClick={() => store.reset()}>复位</button>
    </div>
  );
};

const Root = () => {
  return (
    <StoreProvider store={CountStore}>
      <Child />
    </StoreProvider>
  );
};

API

  • BaseStore

store的基类,提供了 setState 来更新数据

  • StoreProvider

Context Provider 组件,需要把当前的 store 传递给 Provider 组件

  • withStore

StoreProvider 另一种用法, 用法 withStore(Child, CountStore);

const Root = withStore(Child, CountStore);
  • useStore

获取 store 实例,第一个参数是 BaseStore,第二个参数是更新依赖项。

如:

// 调用 setState 组件就会更新
const store = useStore(CountStore);

// 调用 setState 组件不会更新
const store = useStore(CountStore, []);


// 调用 setState 后, count值变化组件会更新,否则不会更新
const store = useStore(CountStore, ['count']);