You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
The key has expired.
New Features
Added the ability to create a store
import{createStore}from'state-pool';conststore=createStore();// You can create as many stores as you want
Integrated useState and useReducer into a store, this allows us to consume our state with store.useState & store.useReducer
Introduced a generic API for implementing state persistence in any storage
store.persist({saveState: function(key,value,isInitialSet){/*your code to save state */},loadState: function(key){/*your code to load state */},removeState: function(key){/*your code to remove state */},clear: function(){/*your code to clear storage */}})
Managing state outside react component(reading and writing state outside react component)
// Reading state outside of React componentstore.getState(key).getValue()// Reading value of a global state from a storeglobalState.getValue()// Reading value of a global state// Listening to store changesconstunsubscribe=store.subscribe(function(key: String,value: Any){// key is the key for a global state that has changed // value is the new value of a global state})// You can unsubscribe by calling the resultunsubscribe();//If you want to listen to a single global state in a store you can use constunsubscribe=store.getState(key).subscribe(function(value){// value is the new value of a global state})// For a plain global stateconstunsubscribe=globalState.subscribe(function(value){// value is the new value of a global state})// You can unsubscribe by calling the resultunsubscribe();// Writing to a global state in a store store.getState(key).updateValue(value=>{// Do your updates here e.g value.name = "Yezy"})// Writing to a plain global stateglobalState.updateValue(value=>{// Do your updates here e.g value.name = "Yezy"})
Breaking Changes
We can no longer import a store from state-pool, we need to import createStore instead.
We can no longer pass a key parameter, persist and default configurations in useGlobalState and useGlobalStateReducer hooks, The key parameter, persist and default configurations are now accepted by store.useState and store.useReducer
store.LOCAL_STORAGE_UPDATE_DEBOUNCE_TIME is no longer used, since we have empowered users to implement state persistence by themselves
useLocalState is removed, since our focus is on managing global state