Skip to content

How to get the current offset value? - Parallax #1729

Answered by kindoflew
Jaay7 asked this question in Support
Discussion options

You must be logged in to vote

Hi! I just looked into it and (although it is not documented) this is sort of a bug! Right now, we are only updating offset when the scrollTo method is called to ensure that we are scrolling from the correct offset.

So, thanks for finding this!

Edit, edit: So, I didn't notice at first that you are attempting to render parallax.current.offset directly in your return. This won't work because the internal state of Parallax is a mutable ref object using a fancy version of useMemo. Because of this, it will never cause a rerender when updated. To get the current value of offset you'd have to have a function that is called when you want to display it. I made an example for another question that …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@Jaay7
Comment options

@slaymantis
Comment options

@kindoflew
Comment options

@chaseliu1313
Comment options

Answer selected by Jaay7
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants