Home > Back-end >  React search for an element from map function and scroll to that location
React search for an element from map function and scroll to that location

Time:05-25

I am trying to search an element from a map function and scroll to the location of that element -

const time = "1235"

return <RightWrapper>
    
    {arr.map((transcript) => (
  <p
    dangerouslySetInnerHTML={createMarkup(transcript)}
    key={transcript.id}
    
  ></p> </RightWrapper>

Here I want to search for value time(which in this case is 12345) in transcript and scroll to that part when there is a match.

CodePudding user response:

I'm not sure if this if how you want it to work but I just tried out a solution that matches that exact value in the list and scrolls to that section of the page.

https://codesandbox.io/s/blue-microservice-yqnz3b?file=/src/App.js

  • Related