
Jotai Has a Free Atomic State Manager: Primitive and Flexible State for React Without Boilerplate
Redux is too much structure for simple state. Context API re-renders everything. Zustand is great but uses a single store. What if you wanted state that's as simple as useState but shared across components? That's Jotai — atomic state management inspired by Recoil, but simpler. The Core Concept: Atoms import { atom , useAtom } from " jotai " ; // Create an atom — like a global useState const countAtom = atom ( 0 ); const nameAtom = atom ( " Aleksej " ); function Counter () { const [ count , setCount ] = useAtom ( countAtom ); return < button onClick = {() => setCount ( c => c + 1 )} > Count : { count } < /button> ; } function NameDisplay () { const [ name ] = useAtom ( nameAtom ); return < p > Hello , { name } < /p> ; } // Both components use global state — no Provider required (with default store) Derived Atoms const priceAtom = atom ( 100 ); const quantityAtom = atom ( 1 ); const taxRateAtom = atom ( 0.2 ); // Read-only derived atom — recomputes when dependencies change const totalAt
Continue reading on Dev.to Webdev
Opens in a new tab



