有没有办法将引用传递给Form.Input组件?

时间:2019-08-29 22:50:52

标签: semantic-ui-react

我正在使用来自“ semantic-ui-react”的Form.Input,并且希望将重点放在提交包含Form的表单上。 “ ref”似乎是从onClick处理程序中获取组件的推荐方法,但是当我将ref传递给Form.Input时,我得到警告:

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
const MyForm = () => {
  const inputRef = useRef(null)
  const handleClick = () => inputRef.current.focus()

  return (
    <Form>
      <Button content="focus" onClick={handleClick} />
      <Form.Input ref={inputRef} />
    </Form>
  );
};

这适用于Input组件而不是Form.Input。看起来像是来自反应的警告,Input是一个类组件,Form.Input是功能性的。尝试将MyForm定义为类组件无济于事。

0 个答案:

没有答案