Skip to content

Commit 23b1f4c

Browse files
authored
Clarify when Consumers get the default value
1 parent 9343241 commit 23b1f4c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

content/docs/context.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const {Provider, Consumer} = React.createContext(defaultValue);
4747

4848
Creates a `{ Provider, Consumer }` pair.
4949

50-
Optionally accepts a default value to be passed to Consumers without a Provider ancestor.
50+
Optionally accepts a default value to be passed to Consumers without a Provider ancestor. _Only Consumers that don't have a Provider higher in the tree receive the default value_.
5151

5252
### `Provider`
5353

@@ -59,6 +59,10 @@ A React component that allows Consumers to subscribe to context changes.
5959

6060
Accepts a `value` prop to be passed to Consumers that are descendants of this Provider. One Provider can be connected to many Consumers. Providers can be nested to override values deeper within the tree.
6161

62+
> Note:
63+
>
64+
> If `value` is not provided, Consumers receive `undefined`. To use the default value in a Consumer instead, remove the Provider altogether.
65+
6266
### `Consumer`
6367

6468
```js

0 commit comments

Comments
 (0)