React Hookie Store
1 step to build your public state module with your custom hook.
Usage
step 1
wrap your app with Store.
// index.tsx; ReactDOM.render Store App / /Store, document.getElementById'app';
step 2
use Store when exporting your custom hook.
// use-userinfo.ts; // use here.;
Everything is Done!
example
Just use your custom hook in normal way. Only one state instance will be created when it is used in two different components.
// A.tsx
other features
- If your component only use its exported function, your component will not be rendered when the state changes.
// A.tsx// Only use the update method. Because the component doesn't watch the change of userinfo state, it should not be re-rendered when state state changes.
- If your component does not need any state or method of the custom hook, it just want to be re-rendered when the state is changed. Just observe it.
// C.tsx// Component will re-render when the userinfo state changes.