Hi, nice article, it helped me to solve a problem.
But I was wondering why you create an array with useRef([]), then create some refs inside that ref who is an array... doesn't that create a ref in a ref?
the problem is that the part const myRefs = things.map(() => createRef()) will be called everytime the component re-render, so, that will change the refs
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, nice article, it helped me to solve a problem.
But I was wondering why you create an array with useRef([]), then create some refs inside that ref who is an array... doesn't that create a ref in a ref?
Couldn't you just make that instead?
Then refer to it like that in the
<button>
:For the first question, I can't remember why I needed to do it that way.
When it comes to refer to them, you have to use .current. So myRefs[i] doesn't work, but myRefs.current[i] will.
the problem is that the part
const myRefs = things.map(() => createRef())
will be called everytime the component re-render, so, that will change the refs