'React Context Api - A Context Passed through Context Provider is yet not able to accessible by Child Components

I have a component ExpandableCard and created its context ExpandableCardContext and context provider ExpandableCardProvider. Then I called the provider from some ParentComponent by passing a prop "handleCloseExpandableCard"(an arrow function) and also another prop "component" have value a ChildComponent which gets called from ExpandableCard. The problem is that ChildComponent doesn't receive "handleCloseExpandableCard" as a prop.

ParentComponent


**ExpandableCardProvider
**

**ExpandableCardContext
**

ExpandableCard
it calls the component(ParcelCardProvider) passed from "ParentComponent" and that ParcelCardProvider is not receiving "handleCloseExpandCard" as a prop.

This is the Error I'm getting. Image With error

My Guess is that parcel card is being called as a prop outside that context but at the same time it's wrapped inside the Context Provider component. Anybody here with help?
Much Appreciated. Thanks.



Solution 1:[1]

I've resolved this one. I was trying to import handleCloseExpandableCard as

const [handleCloseExpandableCard] = useContext(ExpandableCardContext);

but actually it needed to be import like this

const [, , handleCloseExpandableCard] = useContext(ExpandableCardContext);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alitjanjua