You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/learn/managing-state.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -697,11 +697,11 @@ Read **[Extracting State Logic into a Reducer](/learn/extracting-state-logic-int
697
697
698
698
</LearnMore>
699
699
700
-
## Passing data deeply with context {/*passing-data-deeply-with-context*/}
700
+
## Passing data deeply with Context {/*passing-data-deeply-with-context*/}
701
701
702
702
Usually, you will pass information from a parent component to a child component via props. But passing props can become inconvenient if you need to pass some prop through many components, or if many components need the same information. Context lets the parent component make some information available to any component in the tree below it—no matter how deep it is—without passing it explicitly through props.
703
703
704
-
Here, the `Heading` component determines its heading level by "asking" the closest `Section` for its level. Each `Section` tracks its own level by asking the parent `Section` and adding one to it. Every `Section` provides information to all components below it without passing props--it does that through context.
704
+
Here, the `Heading` component determines its heading level by "asking" the closest `Section` for its level. Each `Section` tracks its own level by asking the parent `Section` and adding one to it. Every `Section` provides information to all components below it without passing props--it does that through Context.
Read **[Passing Data Deeply with Context](/learn/passing-data-deeply-with-context)** to learn about using context as an alternative to passing props.
798
+
Read **[Passing Data Deeply with Context](/learn/passing-data-deeply-with-context)** to learn about using Context as an alternative to passing props.
799
799
800
800
</LearnMore>
801
801
802
-
## Scaling up with reducer and context {/*scaling-up-with-reducer-and-context*/}
802
+
## Scaling up with reducer and Context {/*scaling-up-with-reducer-and-context*/}
803
803
804
-
Reducers let you consolidate a component’s state update logic. Context lets you pass information deep down to other components. You can combine reducers and context together to manage state of a complex screen.
804
+
Reducers let you consolidate a component’s state update logic. Context lets you pass information deep down to other components. You can combine reducers and Context together to manage state of a complex screen.
805
805
806
-
With this approach, a parent component with complex state manages it with a reducer. Other components anywhere deep in the tree can read its state via context. They can also dispatch actions to update that state.
806
+
With this approach, a parent component with complex state manages it with a reducer. Other components anywhere deep in the tree can read its state via Context. They can also dispatch actions to update that state.
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/createPortal.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ import { createPortal } from 'react-dom';
42
42
43
43
[See more examples below.](#usage)
44
44
45
-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events bubble up from children to parents according to the React tree.
45
+
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the Context provided by the parent tree, and events bubble up from children to parents according to the React tree.
46
46
47
47
#### Parameters {/*parameters*/}
48
48
@@ -125,7 +125,7 @@ Notice how the second paragraph visually appears outside the parent `<div>` with
125
125
</body>
126
126
```
127
127
128
-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events still bubble up from children to parents according to the React tree.
128
+
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the Context provided by the parent tree, and events still bubble up from children to parents according to the React tree.
Copy file name to clipboardExpand all lines: src/content/reference/react/Component.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,9 +50,9 @@ Only the `render` method is required, other methods are optional.
50
50
51
51
### `context` {/*context*/}
52
52
53
-
The [context](/learn/passing-data-deeply-with-context) of a class component is available as `this.context`. It is only available if you specify *which*context you want to receive using [`static contextType`](#static-contexttype).
53
+
The [Context](/learn/passing-data-deeply-with-context) of a class component is available as `this.context`. It is only available if you specify *which*Context you want to receive using [`static contextType`](#static-contexttype).
54
54
55
-
A class component can only read one context at a time.
55
+
A class component can only read one Context at a time.
56
56
57
57
```js {2,5}
58
58
classButtonextendsComponent {
@@ -565,7 +565,7 @@ class Greeting extends Component {
565
565
566
566
React may call `render` at any moment, so you shouldn't assume that it runs at a particular time. Usually, the `render` method should return a piece of [JSX](/learn/writing-markup-with-jsx), but a few [other return types](#render-returns) (like strings) are supported. To calculate the returned JSX, the `render` method can read [`this.props`](#props), [`this.state`](#state), and [`this.context`](#context).
567
567
568
-
You should write the `render` method as a pure function, meaning that it should return the same result if props, state, and context are the same. It also shouldn't contain side effects (like setting up subscriptions) or interact with the browser APIs. Side effects should happen either in event handlers or methods like [`componentDidMount`.](#componentdidmount)
568
+
You should write the `render` method as a pure function, meaning that it should return the same result if props, state, and Context are the same. It also shouldn't contain side effects (like setting up subscriptions) or interact with the browser APIs. Side effects should happen either in event handlers or methods like [`componentDidMount`.](#componentdidmount)
569
569
570
570
#### Parameters {/*render-parameters*/}
571
571
@@ -714,7 +714,7 @@ React calls `shouldComponentUpdate` before rendering when new props or state are
714
714
715
715
- `nextProps`: The next props that the component is about to render with. Compare `nextProps` to [`this.props`](#props) to determine what changed.
716
716
- `nextState`: The next state that the component is about to render with. Compare `nextState` to [`this.state`](#props) to determine what changed.
717
-
- `nextContext`: The next context that the component is about to render with. Compare `nextContext` to [`this.context`](#context) to determine what changed. Only available if you specify [`static contextType`](#static-contexttype).
717
+
- `nextContext`: The next Context that the component is about to render with. Compare `nextContext` to [`this.context`](#context) to determine what changed. Only available if you specify [`static contextType`](#static-contexttype).
718
718
719
719
#### Returns {/*shouldcomponentupdate-returns*/}
720
720
@@ -789,7 +789,7 @@ If you define `UNSAFE_componentWillReceiveProps`, React will call it when the co
- `nextProps`: The next props that the component is about to receive from its parent component. Compare `nextProps` to [`this.props`](#props) to determine what changed.
792
-
- `nextContext`: The next context that the component is about to receive from the closest provider. Compare `nextContext` to [`this.context`](#context) to determine what changed. Only available if you specify [`static contextType`](#static-contexttype).
792
+
- `nextContext`: The next Context that the component is about to receive from the closest provider. Compare `nextContext` to [`this.context`](#context) to determine what changed. Only available if you specify [`static contextType`](#static-contexttype).
@@ -856,7 +856,7 @@ There is no direct equivalent to `UNSAFE_componentWillUpdate` in function compon
856
856
857
857
### `static contextType` {/*static-contexttype*/}
858
858
859
-
If you want to read [`this.context`](#context-instance-field) from your class component, you must specify which context it needs to read. The context you specify as the `static contextType` must be a value previously created by [`createContext`.](/reference/react/createContext)
859
+
If you want to read [`this.context`](#context-instance-field) from your class component, you must specify which Context it needs to read. The Context you specify as the `static contextType` must be a value previously created by [`createContext`.](/reference/react/createContext)
860
860
861
861
```js {2}
862
862
classButtonextendsComponent {
@@ -1773,9 +1773,9 @@ If your component does not synchronize with any external systems, [you might not
1773
1773
1774
1774
---
1775
1775
1776
-
### Migrating a component with context from a class to a function {/*migrating-a-component-with-context-from-a-class-to-a-function*/}
1776
+
### Migrating a component with Context from a class to a function {/*migrating-a-component-with-context-from-a-class-to-a-function*/}
1777
1777
1778
-
In this example, the `Panel` and `Button` class components read [context](/learn/passing-data-deeply-with-context) from [`this.context`:](#context)
1778
+
In this example, the `Panel` and `Button` class components read [Context](/learn/passing-data-deeply-with-context) from [`this.context`:](#context)
Copy file name to clipboardExpand all lines: src/content/reference/react/apis.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ In addition to [Hooks](/reference/react/hooks) and [Components](/reference/react
10
10
11
11
---
12
12
13
-
*[`createContext`](/reference/react/createContext) lets you define and provide context to the child components. Used with [`useContext`.](/reference/react/useContext)
13
+
*[`createContext`](/reference/react/createContext) lets you define and provide Context to the child components. Used with [`useContext`.](/reference/react/useContext)
14
14
*[`lazy`](/reference/react/lazy) lets you defer loading a component's code until it's rendered for the first time.
15
15
*[`memo`](/reference/react/memo) lets your component skip re-renders with same props. Used with [`useMemo`](/reference/react/useMemo) and [`useCallback`.](/reference/react/useCallback)
16
16
*[`startTransition`](/reference/react/startTransition) lets you mark a state update as non-urgent. Similar to [`useTransition`.](/reference/react/useTransition)
@@ -20,11 +20,11 @@ In addition to [Hooks](/reference/react/hooks) and [Components](/reference/react
20
20
21
21
## Resource APIs {/*resource-apis*/}
22
22
23
-
*Resources* can be accessed by a component without having them as part of their state. For example, a component can read a message from a Promise or read styling information from a context.
23
+
*Resources* can be accessed by a component without having them as part of their state. For example, a component can read a message from a Promise or read styling information from a Context.
24
24
25
25
To read a value from a resource, use this API:
26
26
27
-
*[`use`](/reference/react/use) lets you read the value of a resource like a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context).
27
+
*[`use`](/reference/react/use) lets you read the value of a resource like a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [Context](/learn/passing-data-deeply-with-context).
Copy file name to clipboardExpand all lines: src/content/reference/react/use.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: use
4
4
5
5
<Intro>
6
6
7
-
`use` is a React API that lets you read the value of a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context).
7
+
`use` is a React API that lets you read the value of a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [Context](/learn/passing-data-deeply-with-context).
8
8
9
9
```js
10
10
constvalue=use(resource);
@@ -20,7 +20,7 @@ const value = use(resource);
20
20
21
21
### `use(context)` {/*use-context*/}
22
22
23
-
Call `use` with a [context](/learn/passing-data-deeply-with-context) to read its value. Unlike [`useContext`](/reference/react/useContext), `use` can be called within loops and conditional statements like `if`.
23
+
Call `use` with a [Context](/learn/passing-data-deeply-with-context) to read its value. Unlike [`useContext`](/reference/react/useContext), `use` can be called within loops and conditional statements like `if`.
Copy file name to clipboardExpand all lines: src/content/reference/react/useContext.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: useContext
4
4
5
5
<Intro>
6
6
7
-
`useContext` is a React Hook that lets you read and subscribe to [context](/learn/passing-data-deeply-with-context) from your component.
7
+
`useContext` is a React Hook that lets you read and subscribe to [Context](/learn/passing-data-deeply-with-context) from your component.
8
8
9
9
```js
10
10
constvalue=useContext(SomeContext)
@@ -20,7 +20,7 @@ const value = useContext(SomeContext)
20
20
21
21
### `useContext(SomeContext)` {/*usecontext*/}
22
22
23
-
Call `useContext` at the top level of your component to read and subscribe to [context.](/learn/passing-data-deeply-with-context)
23
+
Call `useContext` at the top level of your component to read and subscribe to [Context.](/learn/passing-data-deeply-with-context)
24
24
25
25
```js
26
26
import { useContext } from'react';
@@ -53,7 +53,7 @@ function MyComponent() {
53
53
54
54
### Passing data deeply into the tree {/*passing-data-deeply-into-the-tree*/}
55
55
56
-
Call `useContext` at the top level of your component to read and subscribe to [context.](/learn/passing-data-deeply-with-context)
56
+
Call `useContext` at the top level of your component to read and subscribe to [Context.](/learn/passing-data-deeply-with-context)
57
57
58
58
```js [[2, 4, "theme"], [1, 4, "ThemeContext"]]
59
59
import { useContext } from'react';
@@ -197,7 +197,7 @@ function MyPage() {
197
197
198
198
Now any `Button` inside of the provider will receive the current `theme` value. If you call `setTheme` to update the `theme` value that you pass to the provider, all `Button` components will re-render with the new `'light'` value.
199
199
200
-
<Recipes titleText="Examples of updating context" titleId="examples-basic">
200
+
<Recipes titleText="Examples of updating Context" titleId="examples-basic">
201
201
202
202
#### Updating a value via Context {/*updating-a-value-via-context*/}
### Optimizing re-renders when passing objects and functions {/*optimizing-re-renders-when-passing-objects-and-functions*/}
1292
1292
1293
-
You can pass any values via context, including objects and functions.
1293
+
You can pass any values via Context, including objects and functions.
1294
1294
1295
1295
```js [[2, 10, "{ currentUser, login }"]]
1296
1296
functionMyApp() {
@@ -1309,7 +1309,7 @@ function MyApp() {
1309
1309
}
1310
1310
```
1311
1311
1312
-
Here, the <CodeStep step={2}>context value</CodeStep> is a JavaScript object with two properties, one of which is a function. Whenever `MyApp` re-renders (for example, on a route update), this will be a *different* object pointing at a *different* function, so React will also have to re-render all components deep in the tree that call `useContext(AuthContext)`.
1312
+
Here, the <CodeStep step={2}>Context value</CodeStep> is a JavaScript object with two properties, one of which is a function. Whenever `MyApp` re-renders (for example, on a route update), this will be a *different* object pointing at a *different* function, so React will also have to re-render all components deep in the tree that call `useContext(AuthContext)`.
1313
1313
1314
1314
In smaller apps, this is not a problem. However, there is no need to re-render them if the underlying data, like `currentUser`, has not changed. To help React take advantage of that fact, you may wrap the `login` function with [`useCallback`](/reference/react/useCallback) and wrap the object creation into [`useMemo`](/reference/react/useMemo). This is a performance optimization:
Copy file name to clipboardExpand all lines: src/content/reference/react/useRef.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -192,7 +192,7 @@ export default function Stopwatch() {
192
192
193
193
React expects that the body of your component [behaves like a pure function](/learn/keeping-components-pure):
194
194
195
-
- If the inputs ([props](/learn/passing-props-to-a-component), [state](/learn/state-a-components-memory), and [context](/learn/passing-data-deeply-with-context)) are the same, it should return exactly the same JSX.
195
+
- If the inputs ([props](/learn/passing-props-to-a-component), [state](/learn/state-a-components-memory), and [Context](/learn/passing-data-deeply-with-context)) are the same, it should return exactly the same JSX.
196
196
- Calling it in a different order or with different arguments should not affect the results of other calls.
197
197
198
198
Reading or writing a ref **during rendering** breaks these expectations.
Copy file name to clipboardExpand all lines: src/content/reference/react/useSyncExternalStore.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,7 +83,7 @@ The current snapshot of the store which you can use in your rendering logic.
83
83
84
84
### Subscribing to an external store {/*subscribing-to-an-external-store*/}
85
85
86
-
Most of your React components will only read data from their [props,](/learn/passing-props-to-a-component) [state,](/reference/react/useState) and [context.](/reference/react/useContext) However, sometimes a component needs to read some data from some store outside of React that changes over time. This includes:
86
+
Most of your React components will only read data from their [props,](/learn/passing-props-to-a-component) [state,](/reference/react/useState) and [Context.](/reference/react/useContext) However, sometimes a component needs to read some data from some store outside of React that changes over time. This includes:
87
87
88
88
* Third-party state management libraries that hold state outside of React.
89
89
* Browser APIs that expose a mutable value and events to subscribe to its changes.
Copy file name to clipboardExpand all lines: src/content/reference/rules/components-and-hooks-must-be-pure.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ This reference page covers advanced topics and requires familiarity with the con
16
16
17
17
One of the key concepts that makes React, _React_ is _purity_. A pure component or hook is one that is:
18
18
19
-
***Idempotent** – You [always get the same result every time](/learn/keeping-components-pure#purity-components-as-formulas) you run it with the same inputs – props, state, context for component inputs; and arguments for hook inputs.
19
+
***Idempotent** – You [always get the same result every time](/learn/keeping-components-pure#purity-components-as-formulas) you run it with the same inputs – props, state, Context for component inputs; and arguments for hook inputs.
20
20
***Has no side effects in render** – Code with side effects should run [**separately from rendering**](#how-does-react-run-your-code). For example as an [event handler](/learn/responding-to-events) – where the user interacts with the UI and causes it to update; or as an [Effect](/reference/react/useEffect) – which runs after render.
21
21
***Does not mutate non-local values**: Components and Hooks should [never modify values that aren't created locally](#mutation) in render.
22
22
@@ -70,7 +70,7 @@ function Dropdown() {
70
70
71
71
## Components and Hooks must be idempotent {/*components-and-hooks-must-be-idempotent*/}
72
72
73
-
Components must always return the same output with respect to their inputs – props, state, and context. This is known as _idempotency_. [Idempotency](https://en.wikipedia.org/wiki/Idempotence) is a term popularized in functional programming. It refers to the idea that you [always get the same result every time](learn/keeping-components-pure) you run that piece of code with the same inputs.
73
+
Components must always return the same output with respect to their inputs – props, state, and Context. This is known as _idempotency_. [Idempotency](https://en.wikipedia.org/wiki/Idempotence) is a term popularized in functional programming. It refers to the idea that you [always get the same result every time](learn/keeping-components-pure) you run that piece of code with the same inputs.
74
74
75
75
This means that _all_ code that runs [during render](#how-does-react-run-your-code) must also be idempotent in order for this rule to hold. For example, this line of code is not idempotent (and therefore, neither is the component):
0 commit comments