Browse Source

Clarify defaultValue usage (#868)

Fixes #867
main
Alex Krolick 7 years ago
committed by GitHub
parent
commit
c95de8b59a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      content/docs/context.md

2
content/docs/context.md

@ -48,7 +48,7 @@ const {Provider, Consumer} = React.createContext(defaultValue);
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. 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.
The `defaultValue` argument is used when you render a Consumer without a matching Provider above it in the tree. This can be helpful for testing components in isolation without wrapping them. The `defaultValue` argument is **only** used by a Consumer when it does not have a matching Provider above it in the tree. This can be helpful for testing components in isolation without wrapping them. Note: passing `undefined` as a Provider value does not cause Consumers to use `defaultValue`.
### `Provider` ### `Provider`

Loading…
Cancel
Save