How can I use ref for the same component which is in the loop?

Issue

array.map((el,i) =>{
      return(
          <Dropzone
          ref = {ref1}
          />
      )
    })

the question is it only ref to the last rendered Dropzone, how can I use ref through loop on all Dropzone component which is render in loop

Solution

try:

  const refs = useRef([]);
  array.map((el,i) =>{
        refs.current[i] = createRef();
          return(
              <Dropzone
               ref={refs.current[i]}
              />
          )
        })

Answered By – Hesam

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.