Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Retrieving the scroll position when the component is removed

$
0
0

In svelte 5, I want to store window.scrollY before the component unmounts to be able to restore it later.

I tried console logging window.scrollY inside onDestroy, the cleanup functions of onMount and $effect(), all of them just gave 0. In React's useLayoutEffect cleanup function you get the correct window.scrollY.

Is there any similar alternative to useLayoutEffect cleanup function in Svelte 5?
I know than we can solve this using event listeners but I just want to do it with effects.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>