最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to fix React Context's object is not a function - TypeError - Stack Overflow

programmeradmin0浏览0评论

I am trying to solve this error for a few days now, I'm trying to pass context to my ponents, 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.

I am trying to solve this error for a few days now, I'm trying to pass context to my ponents, 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.

Share Improve this question asked Oct 5, 2020 at 22:23 ravenousHydraravenousHydra 532 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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.

发布评论

评论列表(0)

  1. 暂无评论