Synchronize React component state with local storage
- Published on
- Published on
- /2 mins read/---
Simple custom hook to synchronize component state with local storage.
use-local-storage-state.ts
In some cases, you might need to check for browser environment, cause local storage is available only in the client side.
use-local-storage-state.ts
Usage
A simple example of using the hook to synchronize component state with local storage is shown below:
theme-switcher.tsx