Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
useContext gives App.js:24 Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

I am using an Auth Context Provider in my App, which is initialised in this file:

authState.js

import React, { useReducer, createContext, useContext } from "react";
import authReducer from "./authReducer";

const initialState = {
  user: null,
};

const AuthContext = createContext();

export const AuthStateProvider = ({ children }) => {
  const [state, dispatch] = useReducer(authReducer, initialState);

  return (
    <AuthContext.Provider value={[state, dispatch]}>
      {children}
    </AuthContext.Provider>
  );
};

export const useAuthContext = () => useContext(AuthContext);

This context is then imported in App.js for getting the user auth details:

App.js

...
...
import { useAuthContext } from './context/auth/authState';
...
...
const [{ user }, authDispatch] = useAuthContext();

I get the error at const [{ user }, authDispatch] = useAuthContext(); line.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found the solution to this, so I console logged useAuthContext() on @vazsonyidl suggestion and received undefined. So the [state,dispatch] were not known to <App/> component. All I did was to wrap my App component within <AuthStateProvider></AuthStateProvider> and it was resolved. Thanks for the suggestion @vazsonyidl.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!