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
When I refresh the page the state is lost with unistore which is similar to redux. React/Redux has middleware libs to persist the state. What are the options with unistore ? I found an interesting article on stackoverflow that talks about saving state to local storage. But things can get messy and the article also mentions about performance issues with frequent state changes.
importcreateStorefrom'unistore';// The top-level state properties you want to persistconstKEYS_TO_SAVE=['foo','bar','baz'];conststore=createStore(loadState()||INITIAL_STATE);// throttle savinglettimer;store.subscribe(()=>{if(timer)return;timer=setTimeout(saveState,100);});functionsaveState(){timer=null;letstate=store.getState();letsaved={};for(constkeyofKEYS_TO_SAVE)saved[key]=state[key];localStorage.setItem('state',JSON.stringify(saved));}functionloadState(){try{returnJSON.parse(localStorage.getItem('state'));}catch(e){}}
When I refresh the page the state is lost with unistore which is similar to redux. React/Redux has middleware libs to persist the state. What are the options with unistore ? I found an interesting article on stackoverflow that talks about saving state to local storage. But things can get messy and the article also mentions about performance issues with frequent state changes.
https://stackoverflow.com/questions/37195590/how-can-i-persist-redux-state-tree-on-refresh
The text was updated successfully, but these errors were encountered: