Skip to content
React·Intermediate·Coding·1 min read

What makes a custom Hook different from an ordinary function?

Short interview answer

A custom Hook calls other Hooks and packages reusable stateful behavior. It shares logic, not one state instance: each component call receives independent hook state unless the hook deliberately connects them to a shared external store.

Example

JSX
function useToggle(initial = false) {  const [on, setOn] = useState(initial);  const toggle = useCallback(() => setOn((v) => !v), []);  return [on, toggle];}// Two components calling useToggle() get two independent states.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to React hooks

Related questions