Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created April 22, 2024 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulieScanlon/43dc32cc04a9bd9b28633c0bb8c2a370 to your computer and use it in GitHub Desktop.
Save PaulieScanlon/43dc32cc04a9bd9b28633c0bb8c2a370 to your computer and use it in GitHub Desktop.
Example local storage component
// 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