|
问题:使用antd组件时,
代码如下 : const [form] = Form.useForm(); 但报如下错误信息: × Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem. 原因: 注意 useForm 是 React Hooks 的实现,只能用于函数组件,class 组件请查看下面的例子。 如果是在 class component 下,你也可以通过 ref 获取数据域。 请注意官方示例下面的说明 解决方案: 参考antd官网,参于class component下,调用的示例方法,不要选择支持函数的示例代码 图片:react.jpg |
|
|
