Ritu Singh
Problem:
The Problem :- The scrollIntoView is working fine but, it fails for this scenario when suppose I click on John Doe it scrolls to that section but now when I scroll to top and select again John Doe then it does not get scrolled to that particular section Why is this happening ? Note :- This happens for all the buttons not just for John Doe
In the useEffect Dependency array I have added the selectedAdvisor state variable so that whenever it changes then it should scrollIntoView of that section based on the id
Expected Output :- scrollIntoView should work properly even if I scroll to top and then select the element that was already selected example John Doe
Below is my code :
CodeSandBoxLink :- >https://codesandbox.io/s/keen-darkness-g42qjw?file=/src/App.js:1443-1470
Where am I going wrong ? please help
Solution:
The issue is that if you select same item after scrolling up, you'll update the state to the same value and the useEffect won't run. Actually, you don't even need an internal state. This would do just fine:
Suggested blogs:
>How you can create array with associative array in other array php?
>How you can send email from a shared inbox in Python
>How you can Show or hide elements in React?
>Instance deployment failed to install Composer dependencies
>Integrate SASS into the build and consume a UI toolkit
>Invoking Python script from scons and pass ARGLIST
>Migrate From Haruko To AWS App: 5 Simple Steps