-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

React Interview Guide
By :

The useContext
Hook is commonly used along with the useState
Hook for global state management. The major advantage of the useContext
Hook is that it solves the prop drilling issue.
Detailed common use cases of the useContext
Hook were already explained in Chapter 2. Hence, this section will mainly focus on specific use case questions related to global state management using the useContext
Hook.
Sometimes, you may need to override the context with a different value for a certain part of the component tree. It is possible to override the context value by wrapping that part in a provider with a different value.
As an example, the following code applies a blue background to all the pages except for the contact page, where a white background will be applied using a context provider:
<ColorContext.Provider value="blue"> <About /> ...