react-scroll-section icon indicating copy to clipboard operation
react-scroll-section copied to clipboard

On unmount `Section` still showing it as a section on `useScrollSections`

Open antoniel opened this issue 4 years ago • 1 comments

Description

When I unmount a Section, I expected that the return of useScrollSections just includes the mounted sections, but it stores all registered sections.

Link to Reproduction

https://codesandbox.io/s/react-scroll-section-unmount-issue-5g2l3?file=/src/App.js

Steps to reproduce

Add more sections and see that it still shows on useScrollSections returns on unmount that section.

Additional Information

A use case that this behavior will impact is building a page's table of contents. If the user navigates over multiple pages, the previous sections will never disappear from the list of content.

antoniel avatar Dec 29 '21 22:12 antoniel

Having the same issue.

As an 'ugly' workarround we reused the Section id forcing the update inside the context.

rpenido avatar Apr 13 '22 00:04 rpenido

As mentioned in the PR #365, this is now fixed :)

Check the code sandbox using the latest version --> https://codesandbox.io/s/react-scroll-section-unmount-issue-forked-ggv9b3?file=/src/App.js

I will proceed to close the issue. Feel free to open it again in case there is something unresolved.

EmaSuriano avatar Oct 16 '22 09:10 EmaSuriano