Scroll position is not persistent when changing state in context.
See original GitHub issueHey!
I’m having an issue with a nonpersistent scroll position when using useState
hook in Context in Gatsby project (same when I use this.setState
). It scrolls to the top after each call.
Demos:
- React (everything works as expected) - preview / video / repo (branch
master
) - Preact - preview / video / repo (branch
with-preact
)
The only difference between those 2 is in using gatsby-plugin-preact
which changes React to Preact during the production build.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Maintaining state and scroll position in react - Stack Overflow
You have to store the scroll position in state on click of post with the use of window.pageYOffset this.setState({ scrollPosition: window.
Read more >Maintain and restore scroll position in React mobile apps
Learn how to maintain React app scroll position when users close a full-page mobile menu to improve UX by implementing a custom Hook....
Read more >Tracking Scroll Position With React Hooks
Today we are going to learn, how to use JavaScript scroll event listener to track browser scroll position using hooks — React not...
Read more >overscroll-behavior - CSS: Cascading Style Sheets | MDN
The overscroll-behavior CSS property sets what a browser does when reaching the boundary of a scrolling area.
Read more >React Hooks — keep scroll position during change list views
During working on one of my projects I met an interesting problem. Let's say you have a list of items which can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirmed! Just updated Preact and 10.4.0 has fixed this issue! 🎉 Thank you, guys!
I’m very sorry, I forgot to come back to this and mention it in my PR. This has been released in 10.4.0.
The gist of it is that we can skip the update of
ParentComponent
because of an optimization better explained here this is used in React and a lot of libraries rely on it.