Clean up of IntersectionObserver on Component Did Unmount #569
-
Hello, Is there a way to manually clean up after the component unmounts? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @andrewcorliss Yes, the Observers are destroyed if they no longer have any active references (from If you need to have control over when the Keep in mind, it will still destroy the observers if they are no longer used after you call Are you sure it's causing issues? |
Beta Was this translation helpful? Give feedback.
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 theobserve()
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 callunmount
whenever your component is destroyed. So not sure if you'd gain anything from it?Are you sure it's causing issues?