How do you use contextType?
- By passing the context value as a prop
- By using the useContext() hook
- By assigning the contextType property in the class definition
- By creating a context consumer
The contextType property is used to consume a context value in a class component in React. To use contextType, you assign the context object to the contextType property in the class definition. This allows the component to access the context value using the this.context property. ContextType can only be used with a single context object and can only be used in class components.
Loading...