← Trail· Lesson 8 of 8
Zustand: global state
Minimal store without boilerplate for shared state.
TODO i18n: Full body translation pending. Title and description are localized; the body below remains in Portuguese for now.
Zustand cria um store com um hook. Qualquer componente pode ler/escrever sem Context excessivo.
import { create } from 'zustand';
const useTheme = create((set) => ({
theme: 'dark',
toggle: () => set((s) => ({ theme: s.theme === 'dark' ? 'light' : 'dark' })),
}));
function App() {
const theme = useTheme((s) => s.theme);
const toggle = useTheme((s) => s.toggle);
return <button type="button" onClick={toggle}>Tema: {theme}</button>;
}