hook-state
v2.0.0
Published
A simple redux-compatible hook-based state library.
Downloads
422
Readme
hook-state
NOTE: The original version of this library was based on Redux. If you want a redux solution for state management with hooks, you can use
use-substate
An experimental hook-based state layer for React that allows sharing state between components.
npm install hook-state
Example
Provider:
import { Provider } from 'hook-state';
<Provider>
<App />
</Provider>;
State reader:
import { useReader } from 'hook-state';
function MyComponent() {
const name = useReader('name');
return <div>My name is {name}</div>;
}
State writer:
import { useWriter } from 'hook-state';
function ChangeName() {
const [name, setName] = useWriter('name', '');
return (
<div>
Change name: <input value={name} onChange={e => setName(e.target.value)} />
</div>
);
}