useEffect and useLayoutEffect
samundrak
JavaScript DevuseEffect and useLayoutEffect
useEffect
- Runs on every update if no dependency array provided
- Runs once if empty array provided
- Runs every time dependency gets changed
useLayoutEffect
Runs synchronously after render is done but before any paint(DOM mutation) is done
- Runs on every update if no dependency array provided
- Runs once if empty array provided
- Runs every time dependency gets changed
Render is not Paint(DOM mutation)
Many time we get confuse with render and DOM mutation. We think when render is called some DOM mutation occurs, which is not true everytime. React calls render function every time when some props or internal states changes but react will only mutate DOM when it thinks the tree it got from render and vdom is different.