RepoPilot

Where in the source is useState defined?

About facebook/react · 2 messages · last activity 8/1/2026

Question

Where in the source is useState defined?

RepoPilot

useState is defined in [packages/react/src/ReactHooks.js:L66-L72].

The implementation shows that useState is an exported function that takes an initialState parameter and delegates to a dispatcher:

export function useState<S>(
  initialState: (() => S) | S,
): [S, Dispatch<BasicStateAction<S>>] {
  const dispatcher = resolveDispatcher();
  return dispatcher.useState(initialState);
}

The actual implementation is delegated to the dispatcher object obtained from resolveDispatcher().

FOLLOW_UPS:

  • What does resolveDispatcher() do in React?
  • How are other hooks like useEffect implemented?
  • Where is the dispatcher implementation located?

Want to ask your own question?

Open chat for facebook/react

Public Q&A. Generated by RepoPilot from the actual source of facebook/react. AI answers can be incomplete or stale — verify before relying on them.