react-state-model
Easy state management with models for react & react-native using hooks. It's useful for global state management and complex components local state
TOC
Install
npm i react-state-model --save
yarn add react-state-model
Model
; const initialState = counter: 0; const getActions = { ; } { if selfcount <= 0 return; ; }; const Store = ;const useGlobal = ; const App = { return <div> <button type="button" onClick=Storedecrease> Decrease </button> <button type="button" onClick=Storeincrease> Increase </button> <OtherComp /> </div> ;}; const OtherComp = { const store = ; return <p>Count:storecounter</p>;};
Class
if you want to use store in class component follow this approach
{ thisunsubscribe = ; } { thisunsubscribe; } { return <p onMouseEnter=Storeincrease onMouseLeave=Storedecrease> Storecount </p> ; }
useLocalStore
Use this instead of useReducer
; const Store = ; const App = { const store = ; return <div> <p> Count: storecounter </p> <button type="button" onClick=storeincrease> Increase </button> </div> ;};