MCPcopy
hub / github.com/facebook/react / useState

Function useState

packages/react-debug-tools/src/ReactDebugHooks.js:280–300  ·  packages/react-debug-tools/src/ReactDebugHooks.js::useState
(
  initialState: (() => S) | S,
)

Source from the content-addressed store, hash-verified

278}
279
280function useState<S>(
281 initialState: (() => S) | S,
282): [S, Dispatch<BasicStateAction<S>>] {
283 const hook = nextHook();
284 const state: S =
285 hook !== null
286 ? hook.memoizedState
287 : typeof initialState === class="st">'function'
288 ? class="cm">// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types
289 initialState()
290 : initialState;
291 hookLog.push({
292 displayName: null,
293 primitive: class="st">'State',
294 stackError: new Error(),
295 value: state,
296 debugInfo: null,
297 dispatcherHookName: class="st">'State',
298 });
299 return [state, (action: BasicStateAction<S>) => {}];
300}
301
302function useReducer<S, I, A>(
303 reducer: (S, A) => S,

Callers 15

EffectWithStateFunction · 0.90
StatefulCounterFunction · 0.90
index.jsFile · 0.90
useOuterFooFunction · 0.90
useInnerFooFunction · 0.90
useInnerBarFunction · 0.90
useInnerBazFunction · 0.90
StatefulFunctionFunction · 0.90
index.jsFile · 0.90
useDebounceFunction · 0.90
index.jsFile · 0.90
List.jsFile · 0.90

Calls 2

nextHookFunction · 0.85
pushMethod · 0.65

Tested by 15

ComponentFunction · 0.72
ComponentFunction · 0.72
useIsDarkModeFunction · 0.72
ComponentFunction · 0.72
ComponentFunction · 0.72
useIsDarkModeFunction · 0.72
ComponentFunction · 0.40
ComponentFunction · 0.40
Component$4Function · 0.40
ComponentFunction · 0.40
ComponentFunction · 0.40
ComponentFunction · 0.40