0.2.14 • Published 1 year ago

idst v0.2.14

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

idst

React store for straightforward shared state management

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

Usage

import {Store, useStore} from 'idst';
  • 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 parts of the shared data: setState({x: 10}); or setState(state => ({x: state.x + 5}));

  • Have as many stores as needed.

Live demo

See also idstm, an immutable store with a mutable interface of setState(). (idstm's setState() is handier when it comes to changing nested properties in the state and it generally results in a more concise code, but it comes with an extra dependency.)

Package name

The package name is the initialism for immutable data store.

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.4

1 year ago

0.2.5

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago