custom hook

Your own function whose name starts with use and that calls other hooks, packaging stateful logic so several components can reuse it.

In more detail

Each component calling a custom hook gets its own independent state; hooks share logic, not data. Good hooks return intent-revealing actions, such as toggle and setTrue, rather than raw setters, and keep returned functions stable with useCallback.

Examples

useFocusTrap(active, containerRef) traps Tab inside a dialog and restores focus on unmount.
function useToggle(initial = false) { ... return { value, toggle, setTrue, setFalse }; }

Related terms

Taught in

References