contextType

Learn how to access values from Context Providers by using the contextType property instead of making a separate Consumer component.

We'll cover the following...

Why use contextType?

While using class components, we can employ a trick that allows us to avoid building another Consumer component bloating our component tree further.

To do this, we can use contextType. It can be assigned to a class component in the form of a static property. The Context value can then be accessed within the component via this.context. The value of the contextType ...