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: beta/src/pages/learn/reacting-to-input-with-state.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -374,7 +374,7 @@ You want to avoid duplication in the state content so you're only tracking what
374
374
Here are some questions you can ask about your state variables:
375
375
376
376
***Does this state cause a paradox?** For example, `isTyping` and `isSubmitting` can't both be `true`. A paradox usually means that the state is not constrained enough. There are four possible combinations of two booleans, but only three correspond to valid states. To remove the "impossible" state, you can combine these into a `status` that must be one of three values: `'typing'`, `'submitting'`, or `'success'`.
377
-
* **Is the same information available in another state variable already?** Another paradox: `isEmpty` and `isTyping` can't be `true` at the same time. By making them separate state variables, you risk them going out of sync and causing bugs. Fortunately, you can remove `isEmpty` and instead check `message.length === 0`.
377
+
* **Is the same information available in another state variable already?** Another paradox: `isEmpty` and `isTyping` can't be `true` at the same time. By making them separate state variables, you risk them going out of sync and causing bugs. Fortunately, you can remove `isEmpty` and instead check `answer.length === 0`.
378
378
***Can you get the same information from the inverse of another state variable?**`isError` is not needed because you can check `error !== null` instead.
379
379
380
380
After this clean-up, you're left with 3 (down from 7!) *essential* state variables:
Copy file name to clipboardExpand all lines: beta/src/pages/learn/rendering-lists.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -390,7 +390,7 @@ Fragments disappear from the DOM, so this will produce a flat list of `<h1>`, `<
390
390
Different sources of data provide different sources of keys:
391
391
392
392
***Data from a database:** If your data is coming from a database, you can use the database keys/IDs, which are unique by nature.
393
-
***Locally generated data:** If your data is generated and persisted locally (e.g. notes in a note-taking app), use an incrementing counter or a package like [`uuid`](https://www.npmjs.com/package/uuid) when creating items.
393
+
***Locally generated data:** If your data is generated and persisted locally (e.g. notes in a note-taking app), use an incrementing counter, [`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID) or a package like [`uuid`](https://www.npmjs.com/package/uuid) when creating items.
@@ -74,7 +73,7 @@ function AppWithCallbackAfterRender() {
74
73
}
75
74
76
75
constcontainer=document.getElementById('app');
77
-
constroot=ReactDOM.createRoot(container);
76
+
constroot=createRoot(container);
78
77
root.render(<AppWithCallbackAfterRender />);
79
78
```
80
79
@@ -297,7 +296,7 @@ If you need to support Internet Explorer we recommend you stay with React 17.
297
296
### React DOM Server {#react-dom-server}
298
297
299
298
***`renderToString`:** Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest `<Suspense>` boundary and then retry rendering the same content on the client. It is still recommended that you switch to a streaming API like `renderToPipeableStream` or `renderToReadableStream` instead.
300
-
***`renderToStaticMarkup`:** Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest `<Suspense>` boundary and retry rendering on the client.
299
+
***`renderToStaticMarkup`:** Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest `<Suspense>` boundary.
Copy file name to clipboardExpand all lines: content/docs/add-react-to-a-website.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ In this section, we will show how to add a React component to an existing HTML p
25
25
26
26
There will be no complicated tools or install requirements -- **to complete this section, you only need an internet connection, and a minute of your time.**
27
27
28
-
Optional: [Download the full example (2KB zipped)](https://gist.github.com/gaearon/6668a1f6986742109c00a581ce704605/archive/f6c882b6ae18bde42dcf6fdb751aae93495a2275.zip)
28
+
Optional: [Download the full example (2KB zipped)](https://gist.github.com/gaearon/6668a1f6986742109c00a581ce704605/archive/87f0b6f34238595b44308acfb86df6ea43669c08.zip)
29
29
30
30
### Step 1: Add a DOM Container to the HTML {#step-1-add-a-dom-container-to-the-html}
31
31
@@ -75,7 +75,7 @@ Open **[this starter code](https://gist.github.com/gaearon/0b180827c190fe4fd98b4
75
75
>
76
76
>This code defines a React component called `LikeButton`. Don't worry if you don't understand it yet -- we'll cover the building blocks of React later in our [hands-on tutorial](/tutorial/tutorial.html) and [main concepts guide](/docs/hello-world.html). For now, let's just get it showing on the screen!
77
77
78
-
After **[the starter code](https://gist.github.com/gaearon/0b180827c190fe4fd98b4c7f570ea4a8/raw/b9157ce933c79a4559d2aa9ff3372668cce48de7/LikeButton.js)**, add two lines to the bottom of `like_button.js`:
78
+
After **[the starter code](https://gist.github.com/gaearon/0b180827c190fe4fd98b4c7f570ea4a8/raw/b9157ce933c79a4559d2aa9ff3372668cce48de7/LikeButton.js)**, add three lines to the bottom of `like_button.js`:
79
79
80
80
```js{3,4,5}
81
81
// ... the starter code you pasted ...
@@ -95,15 +95,15 @@ Check out the next sections for more tips on integrating React.
95
95
96
96
**[View the full example source code](https://gist.github.com/gaearon/6668a1f6986742109c00a581ce704605)**
97
97
98
-
**[Download the full example (2KB zipped)](https://gist.github.com/gaearon/6668a1f6986742109c00a581ce704605/archive/f6c882b6ae18bde42dcf6fdb751aae93495a2275.zip)**
98
+
**[Download the full example (2KB zipped)](https://gist.github.com/gaearon/6668a1f6986742109c00a581ce704605/archive/87f0b6f34238595b44308acfb86df6ea43669c08.zip)**
99
99
100
100
### Tip: Reuse a Component {#tip-reuse-a-component}
101
101
102
102
Commonly, you might want to display React components in multiple places on the HTML page. Here is an example that displays the "Like" button three times and passes some data to it:
103
103
104
104
[View the full example source code](https://gist.github.com/gaearon/faa67b76a6c47adbab04f739cba7ceda)
105
105
106
-
[Download the full example (2KB zipped)](https://gist.github.com/gaearon/faa67b76a6c47adbab04f739cba7ceda/archive/9d0dd0ee941fea05fd1357502e5aa348abb84c12.zip)
106
+
[Download the full example (2KB zipped)](https://gist.github.com/gaearon/faa67b76a6c47adbab04f739cba7ceda/archive/279839cb9891bd41802ebebc5365e9dec08eeb9f.zip)
Copy file name to clipboardExpand all lines: content/docs/error-boundaries.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ Note that **error boundaries only catch errors in the components below them in t
66
66
67
67
## Live Demo {#live-demo}
68
68
69
-
Check out [this example of declaring and using an error boundary](https://codepen.io/gaearon/pen/wqvxGa?editors=0010) with [React 16](/blog/2017/09/26/react-v16.0.html).
69
+
Check out [this example of declaring and using an error boundary](https://codepen.io/gaearon/pen/wqvxGa?editors=0010).
70
70
71
71
72
72
## Where to Place Error Boundaries {#where-to-place-error-boundaries}
Copy file name to clipboardExpand all lines: content/docs/integrating-with-other-libraries.md
+7-5
Original file line number
Diff line number
Diff line change
@@ -192,7 +192,7 @@ class Chosen extends React.Component {
192
192
193
193
React can be embedded into other applications thanks to the flexibility of [`createRoot()`](/docs/react-dom-client.html#createRoot).
194
194
195
-
Although React is commonly used at startup to load a single root React component into the DOM, `root.render()` can also be called multiple times for independent parts of the UI which can be as small as a button, or as large as an app.
195
+
Although React is commonly used at startup to load a single root React component into the DOM, `createRoot()` can also be called multiple times for independent parts of the UI which can be as small as a button, or as large as an app.
196
196
197
197
In fact, this is exactly how React is used at Facebook. This lets us write applications in React piece by piece, and combine them with our existing server-generated templates and other client-side code.
198
198
@@ -246,20 +246,22 @@ You can have as many such isolated components as you like, and use `ReactDOM.cre
246
246
247
247
Below, we will create a Backbone view called `ParagraphView`. It will override Backbone's `render()` function to render a React `<Paragraph>` component into the DOM element provided by Backbone (`this.el`). Here, too, we are using [`ReactDOM.createRoot()`](/docs/react-dom-client.html#createroot):
0 commit comments