React 19 · JSX patterns
Write a custom hook
Extract reusable stateful logic into a function that starts with use.
function useToggle(initial = false) {
const [on, setOn] = useState(initial);
return [on, () => setOn((v) => !v)] as const;
}
Official React 19 documentation