Topic: Scrollspy throws a TypeError due to ref.current being null
Stoofie free asked 5 months ago
Not throw a TypeError and be able to handle cases where current is still null.
Throws a TypeError cannot read properties of null (reading 'offsetTop').
Resources (screenshots, code snippets etc.)
Not sure if this is an issue on my side but we have dynamic scrollspy sections being rendered and thus I've created an array of refs to handle the targets & subsections.
Example code as follow:
This is how I map the array of refs onto the scrollspy components:
Debugging the component's render I can see the .current for the refs are null, however they are changed later on by the components containing the refs as follow: Seeing as refs do not trigger a re-render, how can I get pass this issue?
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
- User: Free
- Premium support: No
- Technology: MDB React
- MDB Version: MDB5 4.0.0
- Device: N/A
- Browser: Chrome
- OS: Windows
- Provided sample code: No
- Provided link: No