useRef挂钩,以专注于Antd输入

问题描述 投票:0回答:1

[我正在尝试使用包装在antd中的无状态功能组件中的<Table>, <Form> <Input>Form.create()()来创建自定义可编辑表。

此刻,每当我在<Input>中输入单个字符或移动鼠标时,该字段就会失去焦点。

我试图通过使用以下方法来关注<Input>

const inputEl = useRef(null);
...
<Input
  ref={inputEl}
  onChange={()=> {inputEl.current.focus()}}
/>

但是那不起作用,因为您无法在focus()上使用<Input>

有什么方法可以使它正常工作?

reactjs react-hooks antd
1个回答
0
投票

您假设Input引用具有focusinput功能,但实际上,由于它是input的实现,因此它在input对象中拥有正确的引用:

© www.soinside.com 2019 - 2024. All rights reserved.