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

Function useOptimistic

packages/react-debug-tools/src/ReactDebugHooks.js:565–585  ·  view source on GitHub ↗
(
  passthrough: S,
  reducer: ?(S, A) => S,
)

Source from the content-addressed store, hash-verified

563}
564
565function useOptimistic<S, A>(
566 passthrough: S,
567 reducer: ?(S, A) => S,
568): [S, (A) => void] {
569 const hook = nextHook();
570 let state;
571 if (hook !== null) {
572 state = hook.memoizedState;
573 } else {
574 state = passthrough;
575 }
576 hookLog.push({
577 displayName: null,
578 primitive: 'Optimistic',
579 stackError: new Error(),
580 value: state,
581 debugInfo: null,
582 dispatcherHookName: 'Optimistic',
583 });
584 return [state, (action: A) => {}];
585}
586
587function useFormState<S, P>(
588 action: (Awaited<S>, P) => S,

Callers 4

FunctionWithHooksFunction · 0.90
FooFunction · 0.50
AppFunction · 0.50
AppFunction · 0.50

Calls 2

nextHookFunction · 0.85
pushMethod · 0.65

Tested by 3

FooFunction · 0.40
AppFunction · 0.40
AppFunction · 0.40