× TypeError: 无法读取未定义的属性“history”
2021-04-24
73
用户已登录,但重定向不起作用。如何解决这些问题?以下是
登录组件代码:
const Login = ({ props }) => {
const [email, setEmail] = useState();
const [password, setPassword] = useState();
const alert = useAlert();
const dispatch = useDispatch();
const { isAuthenticated, error, loading } = useSelector(
(state) => state.auth
);
useEffect(() => {
if (isAuthenticated) {
props.history.push("/");
}
if (error) {
alert.error(error);
dispatch(clearErrors());
}
}, [dispatch, alert, error, loading, props, isAuthenticated]);
const submitHandler = (e) => {
e.preventDefault();
dispatch(login(email, password));
};
return ()
}
错误:
TypeError: Cannot read property 'history' of undefined
1个回答
你从 props 中解构了 props 吗?也许你的意思是
({ history, aProp, bProp })
?
Andrii Lukianenko
2021-04-24