Why are ParentComponent.childContextTypes and ChildComponent.contextTypes needed?

I am at the center of learning React, and after reading about contexts I keep wondering about it. Why is ParentComponent.childContextTypes

it ChildComponent.contextTypes

required that the child component can receive contexts?

+3


source to share


1 answer


The parent component passes the context to this subtree. Therefore, we will indicate which type of your context can be used using the childContextTypes method.

The child component receives context from its parent. In your application, chances are many parent components pass the context as the same names. Thus, you define this type to identify these contexts.



In React JS, the Context API is one of the powerful APIs. So when you need this time, use Context.

0


source







All Articles