Skip to content

Commit dddc2fa

Browse files
Merge pull request #205 from reactjs/sync-5f3a9756
Sync with reactjs.org @ 5f3a975
2 parents 2d335f8 + 778f04c commit dddc2fa

18 files changed

+73
-57
lines changed

beta/src/pages/learn/reacting-to-input-with-state.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ You want to avoid duplication in the state content so you're only tracking what
374374
Here are some questions you can ask about your state variables:
375375

376376
* **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`.
378378
* **Can you get the same information from the inverse of another state variable?** `isError` is not needed because you can check `error !== null` instead.
379379

380380
After this clean-up, you're left with 3 (down from 7!) *essential* state variables:

beta/src/pages/learn/rendering-lists.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ Fragments disappear from the DOM, so this will produce a flat list of `<h1>`, `<
390390
Different sources of data provide different sources of keys:
391391

392392
* **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.
394394

395395
### Rules of keys {/*rules-of-keys*/}
396396

content/blog/2022-03-08-react-18-upgrade-guide.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ render(<App tab="home" />, container);
4040
// After
4141
import { createRoot } from 'react-dom/client';
4242
const container = document.getElementById('app');
43-
const root = createRoot(container);
43+
const root = createRoot(container); // createRoot(container!) if you use TypeScript
4444
root.render(<App tab="home" />);
45-
4645
```
4746

4847
We’ve also changed `unmountComponentAtNode` to `root.unmount`:
@@ -60,7 +59,7 @@ We've also removed the callback from render, since it usually does not have the
6059
```js
6160
// Before
6261
const container = document.getElementById('app');
63-
ReactDOM.render(<App tab="home" />, container, () => {
62+
render(<App tab="home" />, container, () => {
6463
console.log('rendered');
6564
});
6665

@@ -74,7 +73,7 @@ function AppWithCallbackAfterRender() {
7473
}
7574

7675
const container = document.getElementById('app');
77-
const root = ReactDOM.createRoot(container);
76+
const root = createRoot(container);
7877
root.render(<AppWithCallbackAfterRender />);
7978
```
8079

@@ -297,7 +296,7 @@ If you need to support Internet Explorer we recommend you stay with React 17.
297296
### React DOM Server {#react-dom-server}
298297

299298
* **`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.
301300

302301
## Changelog {#changelog}
303302

content/community/conferences.md

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ Do you know of a local React.js conference? Add it here! (Please keep the list c
1212

1313
## Upcoming Conferences {#upcoming-conferences}
1414

15-
### React Miami 2022 🌴 {#react-miami-2022}
16-
April 18 - 19, 2022. Miami, Florida
17-
[Website](https://www.reactmiami.com/)
18-
19-
### < React Global > Online Summit 2022 by Geekle {#react-global-2022}
20-
April 20 - 21, 2022 - Online Summit
21-
22-
[Website](https://events.geekle.us/react2/) - [LinkedIn](https://www.linkedin.com/events/reactglobalonlinesummit-226887417664541614081/)
2315

2416
### Reactathon 2022 {#reactathon-2022}
2517
May 3 - 5, 2022. Berkeley, CA
@@ -46,6 +38,16 @@ June 17 & 21, 2022. In-person in Amsterdam, Netherlands + remote first interacti
4638

4739
[Website](https://reactsummit.com) - [Twitter](https://twitter.com/reactsummit) - [Facebook](https://www.facebook.com/reactamsterdam) - [Videos](https://youtube.com/c/ReactConferences)
4840

41+
### React Norway 2022 {#react-norway-2022}
42+
June 24, 2022. In-person at Farris Bad Hotel in Larvik, Norway and online (hybrid event).
43+
44+
[Website](https://reactnorway.com/) - [Twitter](https://twitter.com/ReactNorway)
45+
46+
### ReactNext 2022 {#react-next-2022}
47+
June 28, 2022. Tel-Aviv, Israel
48+
49+
[Website](https://react-next.com) - [Twitter](https://twitter.com/ReactNext) - [Videos](https://www.youtube.com/c/ReactNext)
50+
4951
### React Native EU 2022: Powered by {callstack} {#react-native-eu-2022-powered-by-callstack}
5052
September 1-2, 2022 - Remote event
5153

@@ -72,6 +74,16 @@ September 29 - October 1, 2022. In-person in Alicante, Spain + remote (hybrid ev
7274

7375
## Past Conferences {#past-conferences}
7476

77+
78+
### < React Global > Online Summit 2022 by Geekle {#react-global-2022}
79+
April 20 - 21, 2022 - Online Summit
80+
81+
[Website](https://events.geekle.us/react2/) - [LinkedIn](https://www.linkedin.com/events/reactglobalonlinesummit-226887417664541614081/)
82+
83+
### React Miami 2022 🌴 {#react-miami-2022}
84+
April 18 - 19, 2022. Miami, Florida
85+
[Website](https://www.reactmiami.com/)
86+
7587
### React Live 2022 {#react-live-2022}
7688
April 1, 2022. Amsterdam, The Netherlands
7789

content/docs/add-react-to-a-website.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ In this section, we will show how to add a React component to an existing HTML p
2525

2626
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.**
2727

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)
2929

3030
### Step 1: Add a DOM Container to the HTML {#step-1-add-a-dom-container-to-the-html}
3131

@@ -75,7 +75,7 @@ Open **[this starter code](https://gist.github.com/gaearon/0b180827c190fe4fd98b4
7575
>
7676
>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!
7777
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`:
7979

8080
```js{3,4,5}
8181
// ... the starter code you pasted ...
@@ -95,15 +95,15 @@ Check out the next sections for more tips on integrating React.
9595

9696
**[View the full example source code](https://gist.github.com/gaearon/6668a1f6986742109c00a581ce704605)**
9797

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)**
9999

100100
### Tip: Reuse a Component {#tip-reuse-a-component}
101101

102102
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:
103103

104104
[View the full example source code](https://gist.github.com/gaearon/faa67b76a6c47adbab04f739cba7ceda)
105105

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)
107107

108108
>Note
109109
>

content/docs/components-and-props.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ const element = <Welcome name="नेहा" />;
6363

6464
उदाहरण के लिए, यह कोड पेज पर रेंडर करता है "नमस्ते, नेहा":
6565

66-
```js{1,5}
66+
```js{1,6}
6767
function Welcome(props) {
6868
return <h1>नमस्ते, {props.name}</h1>;
6969
}
7070
71-
const element = <Welcome name="नेहा" />;
7271
const root = ReactDOM.createRoot(document.getElementById('root'));
72+
const element = <Welcome name="Sara" />;
7373
root.render(element);
7474
```
7575

content/docs/conditional-rendering.md

+10-17
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ function Greeting(props) {
3535
return <GuestGreeting />;
3636
}
3737
38-
ReactDOM.render(
39-
// Try changing to isLoggedIn={true}:
40-
<Greeting isLoggedIn={false} />,
41-
document.getElementById('root')
42-
);
38+
const root = ReactDOM.createRoot(document.getElementById('root'));
39+
// Try changing to isLoggedIn={true}:
40+
root.render(<Greeting isLoggedIn={false} />);
4341
```
4442

4543
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
@@ -110,10 +108,8 @@ class LoginControl extends React.Component {
110108
}
111109
}
112110
113-
ReactDOM.render(
114-
<LoginControl />,
115-
document.getElementById('root')
116-
);
111+
const root = ReactDOM.createRoot(document.getElementById('root'));
112+
root.render(<LoginControl />);
117113
```
118114

119115
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
@@ -140,10 +136,9 @@ function Mailbox(props) {
140136
}
141137
142138
const messages = ['React', 'Re: React', 'Re:Re: React'];
143-
ReactDOM.render(
144-
<Mailbox unreadMessages={messages} />,
145-
document.getElementById('root')
146-
);
139+
140+
const root = ReactDOM.createRoot(document.getElementById('root'));
141+
root.render(<Mailbox unreadMessages={messages} />);
147142
```
148143

149144
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
@@ -244,10 +239,8 @@ class Page extends React.Component {
244239
}
245240
}
246241
247-
ReactDOM.render(
248-
<Page />,
249-
document.getElementById('root')
250-
);
242+
const root = ReactDOM.createRoot(document.getElementById('root'));
243+
root.render(<Page />);
251244
```
252245

253246
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)

content/docs/error-boundaries.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Note that **error boundaries only catch errors in the components below them in t
6666

6767
## Live Demo {#live-demo}
6868

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).
7070

7171

7272
## Where to Place Error Boundaries {#where-to-place-error-boundaries}

content/docs/hello-world.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ next: introducing-jsx.html
99
React का सबसे छोटा उदाहरण ऐसा दिखता है:
1010

1111
```jsx
12-
ReactDOM
13-
.createRoot(document.getElementById('root'))
14-
.render(<h1>नमस्ते, दुनिया!</h1>);
12+
const root = ReactDOM.createRoot(document.getElementById('root'));
13+
root.render(<h1>Hello, world!</h1>);
1514
```
1615

1716
यह पृष्ठ के शीर्षक पर "नमस्ते, दुनिया! दिखाएगा।

content/docs/integrating-with-other-libraries.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Chosen extends React.Component {
192192

193193
React can be embedded into other applications thanks to the flexibility of [`createRoot()`](/docs/react-dom-client.html#createRoot).
194194

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.
196196

197197
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.
198198

@@ -246,20 +246,22 @@ You can have as many such isolated components as you like, and use `ReactDOM.cre
246246

247247
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):
248248

249-
```js{1,5,8-9,13}
249+
```js{7,11,15}
250250
function Paragraph(props) {
251251
return <p>{props.text}</p>;
252252
}
253253
254254
const ParagraphView = Backbone.View.extend({
255+
initialize(options) {
256+
this.reactRoot = ReactDOM.createRoot(this.el);
257+
},
255258
render() {
256259
const text = this.model.get('text');
257-
this.root = ReactDOM.createRoot(this.el);
258-
this.root.render(<Paragraph text={text} />);
260+
this.reactRoot.render(<Paragraph text={text} />);
259261
return this;
260262
},
261263
remove() {
262-
this.root.unmount();
264+
this.reactRoot.unmount();
263265
Backbone.View.prototype.remove.call(this);
264266
}
265267
});

content/versions.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
- title: '18.1.0'
2+
changelog: https://github.com/facebook/react/blob/main/CHANGELOG.md#1810-april-26-2022
13
- title: '18.0.0'
2-
changelog: https://github.com/facebook/react/blob/main/CHANGELOG.md
4+
changelog: https://github.com/facebook/react/blob/main/CHANGELOG.md#1800-march-29-2022
35
- title: '17.0.2'
46
changelog: https://github.com/facebook/react/blob/main/CHANGELOG.md#1702-march-22-2021
57
url: https://17.reactjs.org

examples/context/theme-detailed-app.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ class App extends React.Component {
4646
}
4747
}
4848

49-
ReactDOM.render(<App />, document.root);
49+
const root = ReactDOM.createRoot(
50+
document.getElementById('root')
51+
);
52+
root.render(<App />);

examples/context/updating-nested-context-app.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ function Content() {
4242
);
4343
}
4444

45-
ReactDOM.render(<App />, document.root);
45+
const root = ReactDOM.createRoot(
46+
document.getElementById('root')
47+
);
48+
root.render(<App />);

examples/hello-world.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ReactDOM.render(
2-
<h1>Hello, world!</h1>,
1+
const root = ReactDOM.createRoot(
32
document.getElementById('root')
43
);
4+
root.render(<h1>Hello, world!</h1>);

examples/introducing-jsx.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ const user = {
99

1010
const element = <h1>Hello, {formatName(user)}!</h1>;
1111

12-
ReactDOM.render(element, document.getElementById('root'));
12+
const root = ReactDOM.createRoot(
13+
document.getElementById('root')
14+
);
15+
root.render(element);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const element = <h1>Hello, world</h1>;
21
const root = ReactDOM.createRoot(
32
document.getElementById('root')
43
);
4+
const element = <h1>Hello, world</h1>;
55
root.render(element);

examples/uncontrolled-components/input-type-file.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FileInput extends React.Component {
2828
}
2929
}
3030

31-
ReactDOM.render(
32-
<FileInput />,
31+
const root = ReactDOM.createRoot(
3332
document.getElementById('root')
3433
);
34+
root.render(<FileInput />);

src/site-constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// NOTE: We can't just use `location.toString()` because when we are rendering
99
// the SSR part in node.js we won't have a proper location.
1010
const urlRoot = 'https://reactjs.org';
11-
const version = '18.0.0';
11+
const version = '18.1.0';
1212
const babelURL = 'https://unpkg.com/[email protected]/babel.min.js';
1313

1414
export {babelURL, urlRoot, version};

0 commit comments

Comments
 (0)