react-localstorage-layer
v0.9.0
Published
This package makes localStorage state available to your app. It maintains a shared context that syncs localStorage state updates
Downloads
10
Readme
React LocalStorage Layer
This package makes localStorage state available to your app. It maintains a shared context that syncs localStorage state updates
- Wrap your app with
LocalStorageContextProvider
:
function () {
return (
<LocalStorageContextProvider>
<App />
</LocalStorageContextProvider>
)
}
- Use
useLocalStorageState
to get or set localStorage state
function Example() {
const [n, setN] = useLocalStorageState('n', 0);
return (
<div>
<button onClick={() => setN(n+1)}>{n}</button>
</div>
)
}
- That's mostly it! Now you can use
useLocalStorageState
in any other component. It will stay in sync as you dispatch updates, even across tabs