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

More jsx patterns commands

All jsx patterns commands · React 19 cheatsheet

Was this page helpful?