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

[useScrollTrigger] Do nothing if target is null #45441

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vipierozan99
Copy link

@vipierozan99 vipierozan99 commented Feb 28, 2025

Currently if options.target is undefined it tried to default to the window.

In my case I have another component that may or may not be mounted at a given time, so the ref to it might be null.

Right now I do:

const isScrolled = useScrollTrigger({
  target: containerRef.current ?? undefined,
  threshold: 1,
});

but that will default to the window, and if its not present it will throw an error. Which is not what I want exactly.

This change just disables the hook if null is explicitly passed.

@vipierozan99 vipierozan99 force-pushed the use-scroll-trigger-nullable branch from 87cb731 to 35cab5a Compare February 28, 2025 13:13
@vipierozan99 vipierozan99 force-pushed the use-scroll-trigger-nullable branch from 35cab5a to de8d14d Compare February 28, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant