Last active
April 13, 2024 20:51
-
-
Save pshaddel/43e6a846995ae9731b49f933c4e66168 to your computer and use it in GitHub Desktop.
React Fiber Hooks
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
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