Browse Source

Clarify when Consumers get the default value (#770)

* Clarify when Consumers get the default value

* Change wording
main
Alex Krolick 7 years ago
committed by Dan Abramov
parent
commit
6c22a4345b
  1. 4
      content/docs/context.md

4
content/docs/context.md

@ -45,9 +45,9 @@ Using context, we can avoid passing props through intermediate elements:
const {Provider, Consumer} = React.createContext(defaultValue); const {Provider, Consumer} = React.createContext(defaultValue);
``` ```
Creates a `{ Provider, Consumer }` pair. Creates a `{ Provider, Consumer }` pair. When React renders a context `Consumer`, it will read the current context value from the closest matching `Provider` above it in the tree.
Optionally accepts a default value to be passed to Consumers without a Provider ancestor. The `defaultValue` argument is the context value React uses if you render a `Consumer` without a matching `Provider` above it in the tree. For example, this is helpful for testing components in isolation without wrapping them.
### `Provider` ### `Provider`

Loading…
Cancel
Save