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 | |
| 302 | function 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 | |
| 325 | function useRef<T>(initialValue: T): {current: T} { |
| 326 | const hook = nextHook(); |