🤔 React Remember
Persistent global state in React
👉 Demo 👈
Include the useRemember hook in a component:
const the remember = ;
From anywhere in your application:
;
From anywhere else in your application:
<div>theanswer</div>// displays 42
This value is saved in local storage and will persist until you change or reset it.
Installation & Usage
Install with yarn add react-remember
or npm install react-remember
.
Wrap your top-level app with the Rememberer™:
; const App = { return <Rememberer>/* normal app.js stuff */</Rememberer>;};;
Now you can useRemember in any component. The data will be available everywhere, updatable from anywhere and will persist between refreshes.
// Button.js;const Button = { const the remember = ; return <button onClick= > click me </button> ;}; // Info.js;const Info = { const the remember = ; return <div>Button clicked thecount times</div>;};
Save to URL
The url
prop will store the state in the url rather than localstorage.
<Rememberer url>...</Rememberer>
Defaults
Defaults are the values that are instantiated on first launch.
<Rememberer defaults= count: 42 user: {} > ...</Rememberer>
Explorer
View a list of what's been remembered by adding the show
property to the Rememberer.
<Rememberer show defaults= number: 1 > ...</Rememberer>

FAQ
I thought global state was bad.
Yes.