The difference is following.

useEffect runs asynchronously after the render is committed to the screen.

useLayoutEffect on the other hand based on docs runs:

synchronously after all DOM mutations. Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint.

Because of this if you update screen in useEffect you may notice some blink effect sometimes. Because screen was updated then you immediately updated it again in useEffect.

But most of the times you probably need useEffect. Docs:

Prefer the standard useEffect when possible to avoid blocking visual updates.

Answer from gmoniava on Stack Overflow
🌐
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 - In the code above, the useLayoutEffect hook is used to add smooth scrolling functionality to a container element. An event listener is set up to listen for a scroll event on the window object and invoke the handlescroll function.
🌐
Newline
newline.co › courses › tinyhouse-react-masterclass-part-2 › uselayouteffect-and-window-scroll
Automatically Scroll to Top of Page With React useLayoutEffect - 16.4
January 22, 2020 - The scroll to method of the window object essentially receives coordinate values for the x axis and y axis of the web page by saying zero zero, we're essentially scrolling to the very beginning of the very top left hand corner of the page, which ...
Discussions

reactjs - Is scrolling to bottom after render a good use case for useLayoutEffect? - Stack Overflow
This will run on the 1st time I render my component. I don't want my users to see any flickering (i.e: I just want them to see the "already" scrolled to bottom situation). In this case, will useLayoutEffect allow me to achieve this behavior? More on stackoverflow.com
🌐 stackoverflow.com
What’s the best way to handle scroll with effects hooks?
Essentially to freeze the div you would need to read the current window.scrollY, add the frozen class (which sets position: fixed and overflow: hidden) to the div and immediately scroll it to the scroll position you’ve just read. I tried several implementations, using useEffect, useLayoutEffect, ... More on github.com
🌐 github.com
2
August 4, 2019
Render a div in React with an initial scrollTop value set
So is there any way to set an initial scrollTop value before the component is mounted? ... Why would there be a flicker? componentDidMount is executed before browser updates the screen. Is it an async operation? ... Actually, I'm using the useEffect hook, not componentDidMount, so that's why I'm getting a flicker. ... You can use the useLayoutEffect ... More on stackoverflow.com
🌐 stackoverflow.com
February 24, 2019
Scroll restoration + useLayoutEffect not working
I had a similar issue with a calendar component some time back. I ended up solving it by hiding the component via display initially, and then making it visible within the useEffect, but after setting the scroll position. This got rid of the flash(since it was hidden), and ensured the DOM was indeed painted and available to be scrolled. I don't recall exactly why it was happening but I remember this fixed it. YMMV More on reddit.com
🌐 r/reactjs
6
4
August 16, 2023
🌐
Kent C. Dodds
kentcdodds.com › blog › useeffect-vs-uselayouteffect
useEffect vs useLayoutEffect
December 1, 2020 - This is pretty much the only time you want to avoid useEffect and use useLayoutEffect instead. This runs synchronously immediately after React has performed all DOM mutations. This can be useful if you need to make DOM measurements (like getting the scroll position or other styles for an element) ...
🌐
Medium
medium.com › @ignatovich.dm › deep-dive-into-uselayouteffect-in-react-with-examples-1e3b14da3d4f
Deep Dive into useLayoutEffect in React with Examples | by Frontend Highlights | Medium
October 30, 2024 - Synchronizing scrolling: If you need to scroll to a specific position or adjust layout as a result of user interaction, useLayoutEffect can ensure that changes are applied before the user sees the result.
🌐
GitHub
github.com › facebook › react › issues › 16289
What’s the best way to handle scroll with effects hooks? · Issue #16289 · facebook/react
August 4, 2019 - Essentially to freeze the div you would need to read the current window.scrollY, add the frozen class (which sets position: fixed and overflow: hidden) to the div and immediately scroll it to the scroll position you’ve just read. I tried several implementations, using useEffect, useLayoutEffect, a mix of both or directly manipulating the DOM (ie adding the class manually declaratively).
Author   dbismut
Find elsewhere
🌐
Reddit
reddit.com › r/reactjs › scroll restoration + uselayouteffect not working
r/reactjs on Reddit: Scroll restoration + useLayoutEffect not working
August 16, 2023 -

So I'm implementing scroll restoration in a component that I have. When I run the restoration logic in useEffect, it works, but there's a flash just before it sets the scroll position. This isn't surprising, seeing as useEffect is ran after the browser paints. So I moved the logic into useLayoutEffect to execute before the browser paints, but it doesn't work - I start off at scrollLeft = 0, rather than scrollLeft = whatever it was when I left the page.

I googled around and people reported that useLayoutEffect works for them. I'm not sure why it's not working for me.

I noticed that if I put my canvas.scrollLeft = prevCanvasPos; into a setTimeout (with 0 seconds), it works - except there's a flash. I'm not surprised at the flash, but this seems to indicate to me that it can't scroll to the position before the browser paints, even though the entire DOM is already constructed.

Here's the code:

useLayoutEffect(() => {
    const canvas = canvasRef.current;
    
    const prevCanvasPos: number | undefined = Number(
      localStorage.getItem('canvasPos'),
    );
    
    if (prevCanvasPos && canvas) {
      canvas.scrollLeft = prevCanvasPos;
    }
    
    function setCanvasPos() {
      if (canvas) {
        localStorage.setItem('canvasPos', String(canvas.scrollLeft));
      }
    }
    
    window.addEventListener('beforeunload', setCanvasPos);
    
    return () => {
      if (canvas) {
        localStorage.setItem('canvasPos', String(canvas.scrollLeft));
      }
    
      window.removeEventListener('beforeunload', setCanvasPos);
    };
}, []);

Any suggestions?

🌐
Tech-interview
tech-interview.dev › home › react › use-layout-effect
use-layout-effect - React | Tech Interview Prep Hub
October 19, 2025 - Typical uses: measure and position popovers/tooltips, preserve/restore scroll, manage focus/selection synchronously, and coordinate animations that depend on exact sizes. Keep the work minimal to avoid blocking paint.
🌐
Whoisryosuke
whoisryosuke.com › blog › 2020 › handling-scroll-based-animations-in-react
Handling Scroll Based Animation in React (2-ways) - Ryosuke
Here is where we'll attach the ... when the user scrolls. useLayoutEffect(() => { window.addEventListener("scroll", onScroll); return () => window.removeEventListener("scroll", onScroll); }, []);...
🌐
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 - useLayoutEffect fires synchronously after the DOM mutation and before the browser get to paint the new changes. This hook is especially useful for performing DOM measurement like scroll height, scroll width, scroll position and other style on ...
🌐
DEV Community
dev.to › n8tb1t › tracking-scroll-position-with-react-hooks-3bbj
Tracking Scroll Position With React Hooks - DEV Community
July 9, 2019 - For example, here we start to track the scroll position with the useScrollPosition hook, it will return prevPos and currPos respectively on each position change and will re-render itself on hideOnScroll change, we need this, because hideOnScroll is a stateful variable, which will trigger component re-render on its change triggering the useScrollPosition cleanup routine (componentWillUnmount). useLayoutEffect(() => { window.addEventListener('scroll', handleScroll) return () => window.removeEventListener('scroll', handleScroll) }, deps)
🌐
Dave Ceddia
daveceddia.com › useeffect-vs-uselayouteffect
When to useLayoutEffect Instead of useEffect (example)
July 15, 2020 - There are two React hooks, useEffect and useLayoutEffect, that appear to work pretty much the same.
🌐
GitHub
gist.github.com › joshuacerbito › ea318a6a7ca4336e9fadb9ae5bbb87f4
Custom React hook for listening to scroll events · GitHub
/** * useScroll React custom hook * Usage: * const { scrollX, scrollY, scrollDirection } = useScroll(); */ import { useState, useEffect } from 'react'; import debounce from 'lodash.debounce'; export function useScroll() { const [lastScrollTop, setLastScrollTop] = useState(0); const [bodyOffset, setBodyOffset] = useState( document.body.getBoundingClientRect() ); const [scrollY, setScrollY] = useState(bodyOffset.top); const [scrollX, setScrollX] = useState(bodyOffset.left); const [scrollDirection, setScrollDirection] = useState(); const listener = (e) => { setBodyOffset(document.body.getBoundingClientRect()); setScrollY(-bodyOffset.top); setScrollX(bodyOffset.left); setScrollDirection(lastScrollTop > -bodyOffset.top ?
🌐
KnowledgeHut
knowledgehut.com › home › blog › web development › react uselayouteffect() - hook api reference in react
React useLayoutEffect() - Hook API Reference In React
April 25, 2024 - A useLayoutEffect hook is a React hook that can be passed through in a component's render method to cause the react library to consider the page’s layout and change its calculations for things like spacing and overflow. It is called synchronously once React all DOM modifications. It can be beneficial if you need to take DOM measures (such as the scroll positions or other styles for an element) and then make DOM changes a synchronous re-render by modifying the state.
🌐
Medium
austinrt.medium.com › demystifying-react-hooks-uselayouteffect-eac6773822
Demystifying React Hooks — useLayoutEffect | by austin | Medium
January 7, 2023 - Our chat no longer flickers because, after the value of messages changes, we're blocking the browser from painting the DOM until the useLayoutEffect scrolls the chat to the bottom.