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

Function useReducer

packages/react-debug-tools/src/ReactDebugHooks.js:302–323  ·  packages/react-debug-tools/src/ReactDebugHooks.js::useReducer
(
  reducer: (S, A) => S,
  initialArg: I,
  init?: I => S,
)

Source from the content-addressed store, hash-verified

300}
301
302function useReducer<S, I, A>(
303 reducer: (S, A) => S,
304 initialArg: I,
305 init?: I => S,
306): [S, Dispatch<A>] {
307 const hook = nextHook();
308 let state;
309 if (hook !== null) {
310 state = hook.memoizedState;
311 } else {
312 state = init !== undefined ? init(initialArg) : ((initialArg: any): S);
313 }
314 hookLog.push({
315 displayName: null,
316 primitive: class="st">'Reducer',
317 stackError: new Error(),
318 value: state,
319 debugInfo: null,
320 dispatcherHookName: class="st">'Reducer',
321 });
322 return [state, (action: A) => {}];
323}
324
325function useRef<T>(initialValue: T): {current: T} {
326 const hook = nextHook();

Callers 14

StatefulFunctionFunction · 0.90
SuspenseTreeOperationsFunction · 0.90
useEditableValueFunction · 0.90
ComponentsFunction · 0.90
TreeContextControllerFunction · 0.90
OwnersStack.jsFile · 0.90
SuspenseTab.jsFile · 0.90
ComponentFunction · 0.50
CounterFunction · 0.50

Calls 3

nextHookFunction · 0.85
pushMethod · 0.65
initFunction · 0.50

Tested by 4

ComponentFunction · 0.40
CounterFunction · 0.40
AppFunction · 0.40
ThrowingComponentFunction · 0.40