Hello everyone,
I know people usually go to stackoverflow for problems like this, but i don’t have enough reputation to post a question there, so reddit was my other choice!
I’m currently am trying to rebuild a site i have from html to react. However I stumbled upon a problem while migrating a custom js function to react.
The scenario:
I have a section where the left part is “empty” besides a h2 tag which is supposed to scroll with the user and on the right side is a couple of h3s and text.
Wheres the problem?
I managed to make the function work and everything is good besides the fact that the function uses get element by id/class and when the user navigates using react router, the function still fires and no longer finds these ids and classes thus bringing errors.
In the stackblitz you will find out more info, but essentially i tryed “locking” the function to that “page” specifically but it didnt work out for me (with if pathname.. and trying to “re fire” the function with onclick once the user navigates)
If anyone knows of this problem and gives me some guidence on how to avoid in the future or try to lead me on a workaround, I would be very happy! Thank you in advance!!!
https://stackblitz.com/edit/react-j9qohx?file=src%2Fheader%2FHeader.js
submitted by /u/baychev
[link] [comments]