Question presented to candidate:
"use() is called a hook but it does not follow the Rules of Hooks. What is it and why is it different?"
What a strong answer should cover:
use()reads a resource — a promise or a context — during render. With a promise it suspends until the promise settles; with a context it does whatuseContextdoes.- It is the only hook that may be called conditionally, in a loop, or inside an early return. React documents this explicitly.
- Why it can: it does not hold state on the fiber. Ordinary hooks are matched by position in a linked list, so a conditional call shifts every later hook onto the wrong record.
use()reads something that already exists, so there is no slot to misalign. - With a promise, the promise must be created outside render — a promise created during render is a new one every attempt and never settles.
- A rejected promise read with
use()throws during render, so an error boundary catches it. Pair Suspense (pending) with an error boundary (failed). - It is what makes Server Components able to pass a promise to a Client Component and have it awaited during render.
- It is not a data-fetching library — no caching, no deduplication, no request lifecycle. It only unwraps.
Clarifying questions expected:
- "Where is the promise created?" — that is the correctness question.
- "Is there an error boundary above this, as well as a Suspense boundary?"
Code / implementation expected: Optional. Showing a conditional use() next to a conditional useContext makes the point immediately.