🌐
Kent C. Dodds
kentcdodds.com › blog › useeffect-vs-uselayouteffect
useEffect vs useLayoutEffect
December 1, 2020 - const ref = React.useRef() React.useEffect(() => { ref.current = 'some value' }) // then, later in another hook or something React.useLayoutEffect(() => { console.log(ref.current) // <-- this logs an old value because this runs first! }) So in situations like that, the solution is useLayoutEffect.
🌐
React
react.dev › reference › react › useLayoutEffect
useLayoutEffect – React
Notice that even though the Tooltip component has to render in two passes (first, with tooltipHeight initialized to 0 and then with the real measured height), you only see the final result. This is why you need useLayoutEffect instead of useEffect for this example.
Discussions

When to use useEffect or useLayoutEffect

I will go to my grave believing useEffect is one of the most abused and unecissary hooks a lot of the time.

I'm not saying it doesn't have it's place, but too often people are using it to change data on render, which just causes a new render. Instead they could just isolate the data change from react entirely (which makes sense given react is a view layer and not a full mvc) and have the first render be a cause of the change.

I can't count the number of times I've seen people have a useEffect that checks to see if a useState value changed and loads data based on it. It's like... Just load the data where the useState change was triggered!

More on reddit.com
🌐 r/reactjs
54
133
February 15, 2020
reactjs - Is `useLayoutEffect` preferable to `useEffect` when reading layout? - Stack Overflow
One difference about useLayoutEffect vs useEffect is that useLayoutEffect will be fired synchronously after DOM mutation and before the browser paint phase. (Reference) However, I've came across some More on stackoverflow.com
🌐 stackoverflow.com
React documentation on useLayoutEffect makes me confused
React renders -> useLayoutEffect -> browser renders (draws) -> useEffect More on reddit.com
🌐 r/reactjs
8
9
June 27, 2023
what is the point of `useRef` + `useLayoutEffect` in this scenario?
Why didn't he just directly use option.onSuccess()in his useEffect hook without passing option.onSuccess() in the dependencies array? If option.onSuccess changed, then in the useEffect it would still use the old one More on reddit.com
🌐 r/reactjs
11
12
September 15, 2023
🌐
LogRocket
blog.logrocket.com › home › react uselayouteffect vs. useeffect hooks with examples
React useLayoutEffect vs. useEffect Hooks with examples - LogRocket Blog
June 4, 2024 - If you were to go through a codebase and replace every useEffect call with useLayoutEffect, it would work in most cases. For example, I’ve taken an example from the React Hooks Cheatsheet that fetches data from a remote server and changes the implementation to use useLayoutEffect over useEffect:
🌐
Fishtank
getfishtank.com › insights › understanding-the-differences-useeffect-vs-uselayouteffect
Understanding the Differences: useEffect vs useLayoutEffect | Fishtank
By using useLayoutEffect, we ensure ... a smooth and flicker-free user experience. ... useEffect runs asynchronously after the component has been rendered and painted on the screen....
🌐
Dave Ceddia
daveceddia.com › useeffect-vs-uselayouteffect
When to useLayoutEffect Instead of useEffect (example)
July 15, 2020 - Notice how the version with useLayoutEffect only updates visually once even though the component rendered twice. The useEffect version, on the other hand, visually renders twice, so you see a flicker where the value is briefly 0.
🌐
Telerik
telerik.com › blogs › uselayouteffect-vs-useeffect-react
useLayoutEffect vs. useEffect in React
June 18, 2024 - With useEffect, the callback is executed asynchronously after the component has rendered and the screen has been updated. useLayoutEffect, on the other hand, fires synchronously after all DOM mutations but before the browser has painted the changes.
🌐
Reddit
reddit.com › r/reactjs › when to use useeffect or uselayouteffect
r/reactjs on Reddit: When to use useEffect or useLayoutEffect
February 15, 2020 - An example of the first is updating the page title based on a prop. An example of the second is calculating something based on the height of s tendered div (which you'd actually use useLayoutEffect for as this article so nicely points out)
🌐
JavaScript in Plain English
javascript.plainenglish.io › react-hooks-when-to-use-uselayouteffect-instead-of-useeffect-3271a96d881a
React Hooks - When to Use useLayoutEffect Instead of useEffect | JavaScript in Plain English
July 3, 2023 - The gif below shows two chat boxes — after the page loads, messages are “fetched” and then each chat box scrolls to the bottom. The left box uses the useLayoutEffect hook to scroll to the bottom and the right one uses useEffect. You can ...
Find elsewhere
🌐
Refine
refine.dev › home › blog › tutorials › a guide to using the uselayouteffect hook in react
A Guide to Using the useLayoutEffect Hook in React | Refine
August 12, 2024 - As stated above the useEffect hook is asynchronous this has a significant drawback in that it can only be called after the component has been mounted. This implies that side effects that depend on the layout of the component cannot be carried out using useEffect. Now how do we solve this problem, this is where useLayoutEffect comes in.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › difference-between-useeffect-and-uselayouteffect-hook-in-reactjs
Difference Between useEffect and useLayoutEffect Hook in ReactJS - GeeksforGeeks
July 23, 2025 - We will create a counter and implement it using both useEffect and useLayoutEffect to understand the differences practically. The useEffect is used to perform side effects in function components.
🌐
DEV Community
dev.to › emmanuelthecoder › useeffect-vs-uselayouteffect-the-difference-and-when-to-use-them-124c
useEffect vs useLayoutEffect: the difference and when to use them - DEV Community
January 15, 2024 - This is because useLayoutEffect is fired synchronously after DOM is mutated and before the browser paints the new changes. Okay, I will like you to notice the change well in order to better understand how it works. Let's reference a DOM element with the useRef React hook and let's perform some changes with the two side effect hooks we've been talking about · import React, {useRef, useEffect, useLayoutEffect) from 'react' const App = () => { const inputRef = useRef(null) useEffect(()=>{ inputRef.current.value = "another user" },[]); useLayoutEffect(()=>{ console.log(inputRef.current.value) },[]); return( <div> <input type="text" value="EmmanuelTheCoder" ref= {inputRef}/> </div> ); } export default App;
🌐
GreatFrontEnd
greatfrontend.com › questions › quiz › what-is-the-difference-between-useeffect-and-uselayouteffect-in-react
What is the difference between `useEffect` and `useLayoutEffect` in React? | Quiz Interview Questions with Solutions
September 5, 2021 - useEffect: Runs asynchronously after the DOM has been painted. It is suitable for tasks like data fetching, subscriptions, or logging. useLayoutEffect: Runs synchronously after DOM mutations but before the browser paints.
🌐
Medium
emrebener.medium.com › when-to-use-uselayouteffect-over-useeffect-in-react-e68bd2653282
When to Use useLayoutEffect Over useEffect in React | by Emrebener | Medium
January 31, 2026 - Practical uses for useLayoutEffect are limited, as useEffect will be a better approach for most side effect management scenarios. However, there are times where useLayoutEffect will work better than useEffect.
🌐
Medium
devbysumit.medium.com › useeffect-vs-uselayouteffect-c6eb58bae60b
useEffect vs useLayoutEffect. useEffect and useLayoutEffect are two… | by Sumit kumar Singh | Medium
March 13, 2023 - Use cases: useEffect is used for handling side effects that don't require synchronous updates, such as fetching data from an API, setting up event listeners, or updating the component's state. useLayoutEffect is used for side effects that require ...
🌐
Dead Simple Chat
deadsimplechat.com › blog › uselayouteffect-vs-useeffect-with-examples
useLayoutEffect vs useEffect with examples
October 28, 2023 - In this example we are using the useLayoutEffect to update the tooltip's position with respect to the target element · Clean up function is exactly similar to the useEffect, so you can just reference it in from above.
🌐
Medium
tech.groww.in › useeffect-vs-uselayouteffect-in-plain-language-33eb1c7c1f87
useEffect vs. useLayoutEffect in plain language | by Aakash Sangwan | The Groww Engineering Blog
April 21, 2025 - The difference comes from where useLayoutEffect will be called before the user can see the visual changes in that render whereas useEffect will be called after a user is able to see the visual changes in that render.
🌐
OpenReplay
blog.openreplay.com › useeffect-vs-uselayouteffect-in-react
UseEffect vs UseLayoutEffect in React
April 10, 2023 - So, with their identical syntaxes, what is the difference between these two hooks? Well, there are three key differences: The asynchronous nature of useEffect The DOM flashes The fact that useLayoutEffect is executed before useEffect.
🌐
CodeParrot
codeparrot.ai › blogs › uselayouteffect-vs-useeffect-a-practical-guide-to-react-side-effects
useLayoutEffect vs useEffect: A Practical Guide to React Side Effects
November 5, 2024 - This synchronous behavior makes useLayoutEffect ideal for tasks that require precise control over the DOM’s layout and appearance, helping avoid any visual inconsistencies or flickers. This distinction between uselayouteffect vs useeffect becomes essential in situations where DOM measurements are needed for layout stability. In the example below, useLayoutEffect is used to measure an element’s width immediately after it renders.
🌐
NamasteDev
namastedev.com › home › react › react uselayouteffect vs useeffect
React useLayoutEffect vs useEffect - NamasteDev Blogs
June 1, 2025 - In this case, useLayoutEffect ensures that the height of the div is calculated synchronously and is thus guaranteed to update before the browser paints. This prevents any flickering that could occur if the height adjustment were made in a more ...