Skip to content
Advertisement

Context API problem – object is undefined

I’ve been always using Redux, but I finally decided to try to play with Context API, but apparently I’m missing something. I get an error “TypeError: Object(…)(…) is undefined” in App.js, weather and details appear to be undefined.

Could you please check out my code in order to help me out in finding a mistake? I thought I should have a direct access to the state without the need of destructuring. Or maybe destructuring is the only way to go?

Here you can see all parts of my code – context + wrapped app.js.

MyContext.js

JavaScript

App.js

JavaScript

Everything is wrapped in index.js.

Index.js

JavaScript

Advertisement

Answer

I think you are not importing your context correctly at:

JavaScript

You exported as named in its module, so you need to import it like below:

JavaScript

at app.js file

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement