简体   繁体   English

我收到错误“未捕获的 TypeError:未定义不可迭代(无法读取属性 Symbol(Symbol.iterator))”。 无法找到解决方案

[英]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.

相关问题 获得未定义是不可迭代的(无法读取属性 Symbol(Symbol.iterator)) - getting undefined is not iterable (cannot read property Symbol(Symbol.iterator)) 单击 React NavLink 会导致错误:Uncaught (in promise) TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) - Clicking on React NavLink causes error: Uncaught (in promise) TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) × TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) - × TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) - TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) 未捕获的类型错误:对象在 XMLHttpRequest 中不可迭代(无法读取属性 Symbol(Symbol.iterator))。<anonymous> - Uncaught TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator)) at XMLHttpRequest.<anonymous> Reactjs函数不能正确返回多个值:TypeError:undefined不可迭代(无法读取属性Symbol(Symbol.iterator)) - Reactjs function not returning multiple values properly: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) 使用 React Context API 时出错:“TypeError:Object 不可迭代(无法读取属性 Symbol(Symbol.iterator))” - Error while using React Context API: "TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator))" Storybook 抛出错误:未定义不可迭代(无法读取属性 Symbol(Symbol.iterator)) - Storybook throws error: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) React - 使用 Hooks 时,出现错误 - Object 不可迭代(无法读取属性 Symbol (Symbol.iterator)) - React - When using Hooks, I get an error - Object is not iterable (cannot read property Symbol (Symbol.iterator)) 为什么 Promise.all 的错误?:TypeError:无法读取未定义的属性“Symbol(Symbol.iterator)” - Why the error for Promise.all?: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM