Creating Custom Hooks in React — a practical guide to React custom hooks with clear examples you can reuse in real projects.
React Tutorial Series (35/103). Prefer one article? Read the complete React tutorial.
Short description
Custom hooks share logic, not UI — return values/callbacks.
Custom hook
function useToggle(initial = false) {
const [on, setOn] = useState(initial);
const toggle = () => setOn((v) => !v);
return [on, toggle];
}