Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hello,
I am looking over the documentation and reviewing the code and I am curious if the Observers are cleaned up after navigating away from the components. I am working with an application where I need to keep the observer active for the entire lifecycle and I am thinking it is causing some issues with memory.

Is there a way to manually clean up after the component unmounts?

Thank you

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

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?

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

Thanks,
I will try that.
As for how sure I am still trying to debug the exact cause of the issue. So for now I am trying to reduce any factors that could lead to it.

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.