Created
April 22, 2024 21:18
-
-
Save PaulieScanlon/43dc32cc04a9bd9b28633c0bb8c2a370 to your computer and use it in GitHub Desktop.
Example local storage component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/components/primitive-toggle-local-storage.tsx | |
'use client'; | |
import { useAtom } from 'jotai'; | |
import { darkModeAtom } from '../state'; | |
export const PrimitiveToggleLocalStorage = () => { | |
const [darkMode, setDarkMode] = useAtom(darkModeAtom); | |
const handleToggle = () => { | |
setDarkMode(!darkMode); | |
}; | |
return ( | |
<> | |
<h1>Welcome to {darkMode ? 'dark' : 'light'} mode!</h1> | |
<button onClick={handleToggle}>toggle theme</button> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment