我在使用 React Hook 时遇到了问题 - useDispatch() [英] I got the problem in using React Hook - useDispatch()
本文介绍了我在使用 React Hook 时遇到了问题 - useDispatch()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
反应钩子useDispatch"在函数loginForm"中调用它既不是 React 函数组件,也不是自定义的 React Hook 函数 react-hooks/rules-of-hooks
React Hook "useDispatch" is called in function "loginForm" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
我收到了这种消息.附上代码...
I got this kind of message. Attached code...
import React from 'react'
import { useDispatch} from 'react-redux'
const loginForm = () => {
const dispatch = useDispatch()
return (
<div>lgoinForm</div>
)
}
export default loginForm
推荐答案
将 loginForm
重命名为 LoginForm(组件应以大写字母开头).
Rename loginForm
to LoginForm (component should start with a capital letter).
我已经测试了你的代码,在正确命名组件后它工作正常.
I have tested your code and it works fine after naming the component correctly.
这篇关于我在使用 React Hook 时遇到了问题 - useDispatch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文