DEV Community

Michael Dawson
Michael Dawson

Posted on

Unexpected getSnapshotBeforeUpdate behaviour

So I'm reading the documentation for getSnapshotBeforeUpdate and it quite clearly outlines the exact use case I need it for (moving the scroll position when the page content moves). It also shows an example of reading the previous props (prevProps) and comparing them to the current props (this.props) to see if the number of items in the list has changed. I'm doing the same thing in my application, but I'm getting some odd behavior. Instead of the prevProps having the previous value and this.props having the current values, it behaves like this once then these values both change at once.

For example if I was assigning a prop each letter of the alphabet this is what the outcome would be:

getSnapshotBeforeUpdate call num prevProps this.props
1 a b
2 c c
3 d d

Does this seem like expected behaviour?

The only thing I can think of is that I have this component wrapped in a redux store, so maybe that is doing something funky with the parameters? I'm really at a bit of a loss as to what is going on.

Top comments (0)