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

rc-mini-store

v0.1.1

Published

Mini-store, a simple encapsulated React Context utility component.

Readme

rc-mini-store

一个简单封装React Context的React工具组件。

基本使用

import MiniStore from 'rc-mini-store';
// ...
render() {
  return (
    {/* 创建一个MiniStore,其值由value提供 */}
    <MiniStore.Provider
      storeName="store1"
      value={{
        name: 'nanhai'
        lang: 'react'
      }}
    >
      <p>段落</p>
      {/* B组件订阅store1的数据 */}
      <MiniStore.Consumer storeName="store1">
        <B />
      </MiniStore.Consumer>
    </MiniStore.Provider>
  )
}
// ...

暴露成员

相关伪代码

export function packMiniStoreStates
export function packMiniStoreState
export default {
  Provider: xxx,
  Consumer: xxx,
  packMiniStoreStates,
  packMiniStoreState,
}

packMiniStoreStates(state, context)

一个用以包装 state 类型的 MiniStore 的 value 值,其作用是返回一个对象,使每一个state 的成员(第一层成员)具备一个 set 更改方法。

例如一个组件的 state 为

{
  name: 'nanhai'
}

使用该方法的伪代码如下:

import MiniStore, { packMiniStoreStates } from '...';

packMiniStoreStates(this.state, this);

// 也可以使用MiniStore.packMiniStoreStates(this.state, this);

执行该方法后会返回以下结果

{
  name: 'nanhai',
  setName: (value) => {...}
}

packMiniStoreState(key, value, context)

同 packMiniStoreStates。

packMiniStoreStates 是批量处理 state(处理集合{}),而 packMiniStoreState 则是处理一个 state。

Provider API

| 成员 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | | storeName | 创建出MiniStore的名字,后续订阅组件将会查找这个名字 | string | | | | value | 创建出MiniStore的内容、值,需要传入一个对象。 | { [key: string]: any } | {} | |

Consumer API

| 成员 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | | storeName | 订阅的MiniStore的名字,订阅组件需要在Provider组件的内部,订阅成功后,store的值将会挂载在名为storeName的props下 | string | | |

订阅多个store

不提倡订阅多个 store,可以查看 React 官方文档 Context 一节了解更多, 但仍然你可以利用 MiniStore 来订阅多个 store:

this.state = {
  age: 12
}

// ...

<MiniStore.Provider
  storeName="store1"
  value={{
    ...packMiniStoreStates(this.state, this),
    otherValue: 'something'
  }}
>
  <B />
  <MiniStore.Provider
    storeName="store2"
    value={{
      name: 'nanhai',
      lang: 'react',
      ...MiniStore.packMiniStoreState('size', this.state.size, this)
    }}
  >
    {/* 订阅store1 */}
    <MiniStore.Consumer storeName="store1">
      {/* 订阅store2 */}
      <MiniStore.Consumer storeName="store2">
        <C />
      </MiniStore.Consumer>
    </MiniStore.Consumer>
  </MiniStore.Provider>
</MiniStore.Provider>

订阅组件的使用 订阅了store的组件,将会把订阅的store的所有数据附加至以store名为命名的props上。 即你创建了一个名为goodsStore的仓库,订阅这个仓库的组件,可以在组件内部读取this.props.goodsStore.

this.props.store1.otherValue

this.props.store1.setAge(100)

this.props.store2.name

this.props.store2.setSize('100px')