【发布时间】:2021-07-24 14:51:35
【问题描述】:
我正在使用 react-router-dom 和 redux。我在调度后使用 history.push("/") 但它显示错误。 我希望用户在成功验证后导航到“/”(使用 GOOGLE)
export const googleLogin = () => async (dispatch) => {
try {
const response = await auth.signInWithPopup(provider);
const doc = await db.collection("users").doc(response.user.uid).get();
if (doc.exists) {
await db
.collection("users")
.doc(response.user.uid)
.set(
{
accountDetail: {
emailVerified: response.user.emailVerified,
photoURL: response.user.photoURL,
},
},
{ merge: true }
);
history.push("/")
} else {
await db
.collection("users")
.doc(response.user.uid)
.set({
accountDetail: {
userId: response.user.uid,
displayName: response.user.displayName,
email: response.user.email,
photoURL: auth.currentUser.photoURL,
accountCreatedAt: Date.now(),
},
});
history.push("/")
}
} catch (error) {
await dispatch({ type: AUTH_ERROR, payload: error.message });
}
};
【问题讨论】:
-
错误:- 无效的挂钩调用。 Hooks 只能在函数组件的主体内部调用。这可能是由于以下原因之一: 1. 你可能有不匹配的 React 版本和渲染器(例如 React DOM) 2. 你可能违反了 Hooks 规则 3. 你可能有多个 React 副本同一个应用程序请参阅reactjs.org/link/invalid-hook-call 以获取有关如何调试和修复此问题的提示。在继续之前再次检查
标签: reactjs redux react-redux react-router