CodeZettaInterview Hub

React · Hooks · Junior · Architecture

What is a custom hook?

Short Interview Answer

A function starting with use that composes built-in hooks to reuse stateful logic.

Detailed Explanation

Share behavior, not UI. Return stable APIs. Don't hide surprising side effects.

Example

function useToggle(init = false) {
  const [on, setOn] = useState(init);
  return [on, () => setOn(v => !v)] as const;
}

Did you know this answer?