A reactive state with localstorage and SWR.
npm i --save react-ezglobalstate-hook
or
yarn add react-ezglobalstate-hook
import {
useGlobalState,
setGlobalState
} from 'react-ezglobalstate-hook';
const myState = useGlobalState("unique_key", "default");
setGlobalState("unique_key", "value");
import {
useGlobalState,
setGlobalState
} from 'react-ezglobalstate-hook';
export default function Component(){
//Is this case, Hello World is the primary value if we
//never had stored this value before.
const myState = useGlobalState("myState", "Hello World");
function handleChange(){
setGlobalState("myState", "Good Bye World");
}
return (
<div>
<span>{`Actual value for myState is: ${myState}`}</span>
<button onClick={handleChange}>Change Name</button>
</div>
)
}
MIT