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

I am trying to solve this error for a few days now, I'm trying to pass context to my ponents, what

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745050022a4608329.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信