-
I tried this to display the offset number of the layer but it remains 0 even if I scroll to the about or shop.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi! I just looked into it and (although it is not documented) this is sort of a bug! Right now, we are only updating So, thanks for finding this! Edit, edit: So, I didn't notice at first that you are attempting to render ...
const parallax = useRef();
const handleClick = () => {
if (parallax.current) {
console.log(parallax.current.offset)
}
}
return (
<Parallax ref={parallax}>
<ParallaxLayer onClick={handleClick}>
... This will give you the |
Beta Was this translation helpful? Give feedback.
-
From this way I was able get the current page offset when scrolling. const handleScroll = useCallback(() => { useEffect(() => { ... |
Beta Was this translation helpful? Give feedback.
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 thescrollTo
method is called to ensure that we are scrolling from the correctoffset
.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 yourreturn
. This won't work because the internalstate
ofParallax
is a mutableref
object using a fancy version ofuseMemo
. Because of this, it will never cause a rerender when updated. To get the current value ofoffset
you'd have to have a function that is called when you want to display it. I made an example for another question that …