相关疑难解决方法(0)

How target DOM with react useRef in map

I looking for a solution about get an array of DOM elements with react useRef() hook.

example:

const Component = () => 
{

  // In `items`, I would like to get an array of DOM element
  let items = useRef(null);

  return <ul>
    {['left', 'right'].map((el, i) =>
      <li key={i} ref={items} children={el} />
    )}
  </ul>
}
Run Code Online (Sandbox Code Playgroud)

How can I achieve this?

javascript reactjs react-hooks

13
推荐指数
5
解决办法
7088
查看次数

标签 统计

javascript ×1

react-hooks ×1

reactjs ×1