Reusing logic with custom Hooks in code
function useToggle(initial = false) {
const [on, setOn] = useState(initial);
return { on, toggle: () => setOn(value => !value) };
}Read the example from data and control flow to the resulting UI. Keep the component boundary small.