Added updating nested context default value example (#780)

* added context default value example

* Implement suggested change

* noop function as default value to createContext
This commit is contained in:
tjallingt
2018-04-09 20:12:02 +02:00
committed by Alex Krolick
parent 5ba8e04f26
commit 6521a654cb
2 changed files with 11 additions and 0 deletions

View File

@@ -97,6 +97,9 @@ A more complex example with dynamic values for the theme:
It is often necessary to update the context from a component that is nested somewhere deeply in the component tree. In this case you can pass a function down through the context to allow consumers to update the context:
**theme-context.js**
`embed:context/updating-nested-context-context.js`
**theme-toggler-button.js**
`embed:context/updating-nested-context-theme-toggler-button.js`

View File

@@ -0,0 +1,8 @@
// highlight-range{1-2}
// Make sure the shape of the default value passed to
// createContext matches the shape that the consumers expect!
// highlight-range{2-3}
export const ThemeContext = React.createContext({
theme: themes.dark,
toggleTheme: () => {},
});