【发布时间】:2021-03-20 12:25:29
【问题描述】:
我正在做的是创建一个带有反应钩子的身份验证系统。但是,当我使用反应组件声明和调用常量时,它会返回以下错误。声明常量和/或函数的正确位置是什么?
错误:无法在顶层调用 React Hook “useDispatch”。 React Hooks 必须在 React 函数组件或自定义 React Hook 函数中调用
function handleSubmit({email, password}) {
dispatch(signInRequest(email, password));
}
const dispatch = useDispatch();
class Login extends React.Component {
render() {
return (
<>
//Other code here
</>
);
}
}
export default Login;
【问题讨论】:
标签: reactjs react-redux react-hooks