Skip to content

Clean up of IntersectionObserver on Component Did Unmount #569

Answered by thebuilder
andrewcorliss asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @andrewcorliss

Yes, the Observers are destroyed if they no longer have any active references (from useInView or <InView>), but they are also reused if an observer already exists with the same options.

If you need to have control over when the unmount() happens, then you can use the observe() method directly:
https://github.com/thebuilder/react-intersection-observer#low-level-api

Keep in mind, it will still destroy the observers if they are no longer used after you call unmount, and also that you should call unmount whenever your component is destroyed. So not sure if you'd gain anything from it?

Are you sure it's causing issues?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@andrewcorliss
Comment options

Answer selected by andrewcorliss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants