[英]I am getting an error "Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))". Unable to find solution
const Header = () => {
const firebaseAuth = getAuth(app);
const provider = new GoogleAuthProvider();
const [{user}, dispatch] = useStateValue();
const login = async () =>{
const {
user: { refreshToken, providerData },
} = await signInWithPopup(firebaseAuth, provider);
dispatch({
type: actionType.SET_USER,
user: providerData[0],
});
};
import React, { createContext, useContext, useReducer } from "react";
export const StateContext = createContext();
export const StateProvider = ({ reducer, initialState, children }) => (
// initial state is already defined as user : null
// children is basically our component
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
);
// Custome Hook
export const useStateValue = () => {
useContext(StateContext);
};
I am using context api to create a data layer at the top of all components.我正在使用上下文 api 在所有组件的顶部创建一个数据层。 But I am trying that when the user logged in the user information stored in a state and gets updated.
但是我正在尝试当用户登录存储在 state 中的用户信息并得到更新时。 But here I am getting an error at
const [{user}, dispatch] = useStateValue();
但是在这里我在
const [{user}, dispatch] = useStateValue();
处遇到错误
The problem was in where useStateValue was defined.问题出在定义 useStateValue 的地方。 I actually mistakenly add curley braces while making a custom hook
我实际上在制作自定义钩子时错误地添加了花括号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.