RepoPilot

Where in the source is useState defined?

About facebook/react · 2 messages · last activity 7/26/2026

Question

Where in the source is useState defined?

RepoPilot

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

The function is exported as:

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

It takes an initial state (either a value or a function that returns a value) and delegates to a dispatcher's useState implementation, returning a tuple with the state value and a dispatch function.

FOLLOW_UPS:

  • What does resolveDispatcher return?
  • How does useState handle functional initial state?
  • Where is the Dispatch type defined?

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.