Skip to content
Advertisement

Tag: use-context

Why am I getting undefined prop?

Below is my Header component in react: I have used ContextAPI for efficient state Management.CryptoState is used for this purpose.I have imported the state in Header and getting the necessary props using object-destructuring. Below is my Context-file: I am getting this error in Header component:Header.js:8 Uncaught TypeError: Cannot destructure property ‘currency’ of ‘(0 , _CryptoContext__WEBPACK_IMPORTED_MODULE_1__.CryptoState)(…)’ as it is undefined. Answer

react context is giving undefined object

In my react application I am trying to use context api. In my component I am importing the context but it is giving error that object can not destructure the property. I am trying to implement cart functionality in my app. I am using hooks. ImgContext.js ImageGrid.js Answer You are not providing a a default value when creating the context.

Advertisement