Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Issue with Usescroll works in codesandbox but not in local environment #2851

Open
anasak-dev opened this issue Oct 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@anasak-dev
Copy link

I am encountering an issue with the useScroll hook from Framer Motion when trying to set its target via a ref that is assigned using querySelector. The implementation works perfectly in CodeSandbox, but it fails in my local environment, where it always calculates the entire window height instead of the targeted element.

Steps to Reproduce:

Set up a project using Framer Motion and implement useScroll.
Use querySelector to target a specific div element and pass it to useScroll.
Observe the behavior in CodeSandbox (working) vs. local environment (not working).

Here’s a codesandbox link
https://codesandbox.io/p/sandbox/usescroll-framer-motion-issue-queryselector-4755kc
)

Expected Behavior:

The useScroll hook should calculate the scroll position relative to the targeted div.

Actual Behavior:

In the local environment, the hook calculates the scroll position based on the entire window height, rather than the targeted element.

Additional Information:

I observe on local environment usescroll gives this error

You have defined a container options but the provided ref is not yet hydrated, probably because it's defined higher up the tree. Try calling useScroll() in the same component as the ref, or setting its layoutEffect: false option.

and when I use layoutEffect:false it will not change anything and still calculate whole page scroll progress.

@anasak-dev anasak-dev added the bug Something isn't working label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant