122 components
Persist state to localStorage with automatic serialization
localStorage['user-name'] = ""localStorage['user-settings'] = {
"theme": "light",
"notifications": true,
"autoSave": false
}Persistence: These values are stored in localStorage and will persist even after you refresh the page or close the browser. Try refreshing to see!
const [settings, setSettings] = useLocalStorage('user-settings', {
theme: 'dark',
notifications: true
});
// Updates both state and localStorage
setSettings({ ...settings, theme: 'light' });Import