React如何给列表的每个子项设置ref?

  • Post author:
  • Post category:其他


const Demo = () => {
    const refList = useRef([]);
    return (
        <>
            {arr.map((item, idx) => (<A ref={node => { refList.current[idx] = node }} />))}
        </>
    )
}
//点击事件里拿到每个ref
const handleEdit = (index,item) => {
  refList.current[index].focus({
    cursor: 'end',
  });
}



版权声明:本文为weixin_45644355原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。