use-local-storage-value
Use localStorage value as react state, sync state across opened tabs
Import
Source
Docs
Package
Usage
use-local-storage-value allows you to use value from localStorage as react state. Hook works exactly the same as useState, but also writes value to local storage:
Example
Mantine docs website uses this hook to store color scheme information:
Browser tabs synchronization
use-local-storage-value subscribes to storage event.
When state changes in one tab it automatically updates value in all other opened browser tabs.
You can test this feature by opening 2 tabs with Mantine docs side by side and changing color scheme
(button on the top right or ⌘ + J
on mac and Ctrl + J
on Windows and Linux).
TypeScript
Definition
Set value type
You can specify value type same as in useState hook, type must extend string:
Feedback
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback