Reputation: 53
I am trying to solve this error for a few days now, I'm trying to pass context to my components, whatever I try, I get the error "The object is not a function" or "The object is not iterable"
I was trying to do this with Typescript, and I thought it might be something else, so I tried using react javascript cli and here are the errors below with my code pictures.
Upvotes: 2
Views: 7824
Reputation: 55613
The value of the context is {state,setState}
not [state,setState]
Just do this:
console.log(useContext(GlobalContext))
and you will see that the context is an object with two properties - state
and setState
as given by this line:
<GlobalContext.Provider value={{state,setState}}>
Also, post code, don't post pictures of code.
Upvotes: 4