idstm

0.1.13 • Public • Published

idstm

React store for straightforward shared state management

Dealing with shared state similarly to React's useState().

Usage

import {Store, useStore} from 'idstm';
  • Wrap up shared data into new Store(data), put it into a React Context;

  • Pick the store from the context with the React's useContext() hook from within a component;

  • Read the store state and subscribe to its updates: let [state, setState] = useStore(store); Alternatively, use let [state, setState] = useStore(store, false); (with the hook's second parameter) to turn off the subscription to store state updates;

  • Update the immutable store state via the mutable interface of setState(): setState(draftState => { draftState.x += 5; });

  • Have as many stores as needed.

Live demo

See also idst, an immutable store without the mutable interface of setState().

Package name

The package name is the initialism for immutable data store with a mutable interface.

Readme

Keywords

Package Sidebar

Install

npm i idstm

Weekly Downloads

2

Version

0.1.13

License

ISC

Unpacked Size

4.8 kB

Total Files

5

Last publish

Collaborators

  • axtk