Hook flow
But what exactly is the React Hook Flow?

React Hooks flow includes:
Mount
Update (when state changes based on any event)
UnMount
Definition
Render
Once the lazy initializers are called react renders the JSX defined in the return Statement of the component to its Virtual DOM.
React updates DOM
Once the Virtual DOM is updated React updates the real DOM.
Cleanup LayoutEffects
If you have defined a useLayoutEffect which is a very rare case, react will call the function returned from the hook. You can read more about cleanup functions in the official React docs.
Run LayoutEffects
This Phase executed the code inside a useLayoutEffect hook.
Browser paints screen
In this Phase, the Browser paints the updated DOM screen.
Cleanup Effects
In here the functions returned in the useEffect hook get executed.
Run Effects
This Phase executed the code inside a useEffect hook.
Phases
Mount:
Run the lazy initializer (functions passed to useState or useReducer)
Continue the rest of the render function
React updates the DOM
It runs LayoutEffects
Browser paints the screen to reflect
Runs the effects
Update: (When the user make any event it update the state)
Runs the render phase
React updates DOM
Cleanup LayoutEffects first
Run LayoutEffects
Browser paints the screen
Cleanup the effects first
Run the effects in the render
Unmount: Component gets removed from the screen (navigate to other screen or from user event)
Cleanup LayoutEffects
Cleanup Effects
Never confuse them with lifecycle methods in Class Components.
A great example of hook flow i found is Kent c dodds example :
References and articles :
Last updated
Was this helpful?