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

Able to stop observing with nullish callback #889

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

hooriza
Copy link
Contributor

@hooriza hooriza commented Mar 21, 2022

There is no way to stop intersection observing now.
So I want to able to it with this change.

const handleObserve = useCallback(() => {}, []);
const [isObserving, setIsObserving] = useState(true);

const intersectionObserverRef = useIntersectionObserverRef(isObserving ? handleObserve : undefined);

return (
    <div>
        <div ref={intersectionObserverRef}>target</div>
        <button onClick={() => setIsObserving(false)}>stop observing</button>
    </div>
);

@imbhargav5
Copy link
Owner

This makes sense. But I am just going to think over the API for a bit and see if there is anything else we can do here or come up with a slightly different API.

@codecov
Copy link

codecov bot commented Mar 21, 2022

Codecov Report

Merging #889 (4c2ce61) into main (1a66ed3) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #889   +/-   ##
=======================================
  Coverage   91.09%   91.09%           
=======================================
  Files          67       67           
  Lines        3929     3929           
  Branches      662      662           
=======================================
  Hits         3579     3579           
  Misses        346      346           
  Partials        4        4           
Impacted Files Coverage Δ
src/hooks/useIntersectionObserverRef.ts 75.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a66ed3...4c2ce61. Read the comment docs.

@imbhargav5
Copy link
Owner

Cool this makes sense to me.

@imbhargav5 imbhargav5 merged commit 41996bf into imbhargav5:main Mar 21, 2022
@github-actions
Copy link
Contributor

🎉 This PR is included in version 5.10.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants