DEV Community

loading...

Discussion on: Create section navigation with React and Intersection Observer

Collapse
rehre profile image
Akmal Maulana Azzam

Nice article !, but i think you should try to disconnect or remove the old observer first every update, if not the useEffect will always try to make a new observer and keep watching an old ones and could be a big problem for the performance, i have tried to create your project with the improved observer in here: codesandbox.io/s/section-navigatio... (you should try the site in the real browser tab, i don't know why but when i scroll in the codesandbox viewer the handleIntersection is always running), maybe you can take a look :)

Collapse
maciekgrzybek profile image
Maciek Grzybek Author

Hi Akmal, thanks for the comment. Good spot, I totally forgot about it :) I've already updated example code and the demo. Not sure what do you mean about that Codesandbox example though. Looks like the code it's spot on. Could you explain? Thanks :)

Collapse
rehre profile image
Akmal Maulana Azzam

its okay, i think its just a bug on the scrolling in the codesandbox viewer window, should be okay if i open the project in the real browser window :)