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
Use any implementation of W3C WebStorage API directly as a React/Flux-style store.
varWebStorage=require('react-webstorage'),dispatcher=require('./path/to/app-dispatcher');varwebStorage=newWebStorage(window.localStorage||window.sessionStorage/* or poly-fill thereof */);dispatcher.register(function(payload){switch(payload.actionType){case'A':
webStorage.setItem(payload.key,payload.item);break;case'B':
webStorage.removeItem(payload.key);break;case'C':
webStorage.clear();break;default:
return;}});// Later, inside a component...
getInitialState: function(){return{foo: webStorage.getItem('foo');};},updateState: function(){this.setState({foo: webStorage.getItem('foo')});},componentDidMount: function(){webStorage.addListener('change',this.updateState);},componentWillUnmount: function(){webStorage.removeListener('change',this.updateState);}
WebStorage Instance implements the WebStorage API, and in cases where the contents of WebStorage is modified (setItem, removeItem, clear) fires a change event to registered listeners.