Photo by Mike Lewis HeadSmart Media
February 16, 2019, the React team has introduced React hooks, special functions that can make developers use features that previously only available on the class component (e.g, state, lifecycle) in the function component. React hooks make community to migrate from class component to function component
One of the common hooks is useEffect that can enable side effect in function component. So it can imitate the functionality of lifecycle method like componentWillMount, componentDidMount, componentWillReceiveProps, shouldComponentUpdate, componentDidUpdate, and componentWillUnmount that we usually use in class component
After we replace all lifecycle method with useEffect, is that function component still has lifecycle ? The answer is yes, and here is the diagram that explains lifecycle of the function component that we call "Hooks Flow"

Confuse ? ok, lets explain it one by one
Mount phase is the phase that happens when a component is rendered for the first time. Here is what happens when a component is mounting :
At this step, we run lazy initializers, the function that we pass to useState and useReducer
React will render the component that we create, and doing reconcilation to know what is the difference between React component object and the DOM
After React know what is the difference between the component object and the DOM, React will commit that difference to the DOM
Layout effect is the function that we write in useLayoutEffect. So this function will be called before the browser paint the changes that we made to the screen
After running the layout effect, the browser will paint the changes that we made to the screen
The screen is changed, now is the time to run the function that we write in useEffect
Update phase happens when a component is rerendered, whatever it rerendered because of changes of the props, changes of the state, or because the parent component is rerendered. Here is what happens when a component is updating
React will render the component function to get the component object and doing reconcilation to know what is the difference between React component object and the DOM
After React know what is the difference between the component object and the DOM, React will commit that difference to the DOM
At the update phase, before we run the layout effect, we have to clean up the layout effect by running the function that we returned at useLayoutEffect
Layout effect is the function that we write in useLayoutEffect. So this function will be called before the browser paint the changes that we made to the screen
After running the layout effect, the browser will paint the changes that we made to the screen
At the update phase, before we run effect, we have to clean up the effect by running the function that we returned at useEffect
The screen is changed, now is the time to run the function that we write in useEffect
Unmount phase happens when a component is removed from DOM. Here is what happens
Before the component removed, React will run the cleanup layout effect by running the returned function inside useLayoutEffect
After running the layout effect, React will run the cleanup effect by running the returned function inside useEffect