question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll position is not persistent when changing state in context.

See original GitHub issue

Hey!

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:

  1. React (everything works as expected) - preview / video / repo (branch master)
  2. 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
thomkrupacommented, Apr 20, 2020

Confirmed! Just updated Preact and 10.4.0 has fixed this issue! 🎉 Thank you, guys!

2reactions
JoviDeCroockcommented, Apr 20, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found