I
I
Ignatiy22019-06-29 12:59:34
React
Ignatiy2, 2019-06-29 12:59:34

How to get an array of elements with the same ref attribute?

I have multiple DOM elements with the same ref. If you use the usual React.createRef() function, then this.myRef.current will return the last of the elements. Is there any way to return an entire array of elements, like document.querySelectorAll does?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-06-29
@Ignatiy2

One way to get a link to an element is to use a callback - inside which you can fill in the array you are interested in. For example .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question