I looking for a solution about get an array of DOM elements with react useRef() hook.
example:
const Component = () =>
{
// In `
If you know the length of the array ahead of time, to which you do in your example you can simply create an array of refs and then assign each one by their index:
const Component = () => {
const items = Array.from({length: 2}, a => useRef(null));
return (
{['left', 'right'].map((el, i)) => (
- {el}
)}
)
}