Skip to content

Instantly share code, notes, and snippets.

@pshaddel
Last active April 13, 2024 20:36
Show Gist options
  • Save pshaddel/526d80ab045d998e7574c8d40956d656 to your computer and use it in GitHub Desktop.
Save pshaddel/526d80ab045d998e7574c8d40956d656 to your computer and use it in GitHub Desktop.
Mount State Function
function mountState<S>(
initialState: (() => S) | S,
): [S, Dispatch<BasicStateAction<S>>] {
const hook = mountStateImpl(initialState);
const queue = hook.queue;
const dispatch: Dispatch<BasicStateAction<S>> = (dispatchSetState.bind(
null,
currentlyRenderingFiber,
queue,
): any);
queue.dispatch = dispatch;
return [hook.memoizedState, dispatch];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment