Next.js Discord

Discord Forum

useLayoutEffect now working as expected

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
Hello,

I'm trying show/hide a scroll button based on wether another element is overflowing or not. So naturally the logic should go inside of a useLayoutEffect hook so it's done before the browser paint to avoid flickering. But it's not working as expected, the button does not show right away. I'm wondering if it's Next.js SSR at play (even though it's a client component). Please have a look at the example code below and let me know what could be wrong.

https://stackblitz.com/edit/stackblitz-starters-h5gdk5?file=app%2Fcomponent.tsx

Thanks.

0 Replies