-
|
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
offsetwhen thescrollTomethod 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.offsetdirectly in yourreturn. This won't work because the internalstateofParallaxis a mutablerefobject using a fancy version ofuseMemo. Because of this, it will never cause a rerender when updated. To get the current value ofoffsetyou'd have to have a function that is called when you want to display it. I made an example for another question that …