useLocalStorage
Sync state to localStorage so it persists across reloads.
Current Theme in Storage:dark
Try reloading the page, or clicking a different link in the sidebar. Notice how the whole site theme changes globally because it's wrapped in our ThemeProvider using this exact hook!
Usage Example
1import { useLocalStorage } from '@danixsoft/hooks';
2
3function ThemeToggle() {
4 const [theme, setTheme] = useLocalStorage('theme', 'dark');
5
6 return (
7 <button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
8 Current Theme: {theme}
9 </button>
10 );
11}