October 2019
Intermediate to advanced
426 pages
11h 49m
English
With React context, it is also possible to define multiple providers for the same context. Using this technique, we can override the context value in certain parts of our app. Let's consider the earlier example, and add a second header to it:
const App = () => ( <ThemeContext.Provider value={{ primaryColor: 'coral' }}> <Header text="Hello World" /> <Header text="This is a test" /> </ThemeContext.Provider>)export default App
const App = () => ( <ThemeContext.Provider value={{ primaryColor: 'coral' }}> <Header text="Hello World" /> <ThemeContext.Provider value={{ primaryColor: 'deepskyblue' }}> <Header ...Read now
Unlock full access