Skip to content

Instantly share code, notes, and snippets.

@pshaddel
Last active April 13, 2024 20:51
Show Gist options
  • Save pshaddel/43e6a846995ae9731b49f933c4e66168 to your computer and use it in GitHub Desktop.
Save pshaddel/43e6a846995ae9731b49f933c4e66168 to your computer and use it in GitHub Desktop.
React Fiber Hooks
let currentHook: Hook | null = null;
let workInProgressHook: Hook | null = null;
function mountWorkInProgressHook(): Hook {
const hook: Hook = {
memoizedState: null,
baseState: null,
baseQueue: null,
queue: null,
next: null,
};
if (workInProgressHook === null) {
// This is the first hook in the list
currentlyRenderingFiber.memoizedState = workInProgressHook = hook;
} else {
// Append to the end of the list
workInProgressHook = workInProgressHook.next = hook;
}
return workInProgressHook;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment