r/reactjs •

[deleted by user]

[deleted] — view deleted post

0 Upvotes

255 comments sorted by

View all comments

Show parent comment

1

u/Awnry_Abe Sep 23 '20

Yes, your question makes perfect sense. It's a classic SPA problem. You'll need to elevate state higher than the route. Don't couple scroll position to fetched data. useSWR has an infinite scroll hook that might handle the elevation of the fetched data. It would do so by using its cache. For the scroll position, use element.scollIntoView. Determining what to scroll to would use that elevated piece of state to find the element.