Created
April 13, 2024 20:38
-
-
Save pshaddel/3f7926d7f16ba7f83c83925c3e3af08b to your computer and use it in GitHub Desktop.
mountStateImpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mountStateImpl<S>(initialState: (() => S) | S): Hook { | |
const hook = mountWorkInProgressHook(); | |
if (typeof initialState === 'function') { | |
const initialStateInitializer = initialState; | |
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types | |
initialState = initialStateInitializer(); | |
if (shouldDoubleInvokeUserFnsInHooksDEV) { | |
setIsStrictModeForDevtools(true); | |
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types | |
initialStateInitializer(); | |
setIsStrictModeForDevtools(false); | |
} | |
} | |
hook.memoizedState = hook.baseState = initialState; | |
const queue: UpdateQueue<S, BasicStateAction<S>> = { | |
pending: null, | |
lanes: NoLanes, | |
dispatch: null, | |
lastRenderedReducer: basicStateReducer, | |
lastRenderedState: (initialState: any), | |
}; | |
hook.queue = queue; | |
return hook; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment