Skip to content

Commit a7d2254

Browse files
authored
Update more examples for 18 (reactjs#4607)
* Update more examples for 18 * blargh
1 parent 2a8e0a7 commit a7d2254

File tree

11 files changed

+33
-20
lines changed

11 files changed

+33
-20
lines changed

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ When React sees an element representing a user-defined component, it passes JSX
6464

6565
For example, this code renders "Hello, Sara" on the page:
6666

67-
```js{1,5}
67+
```js{1,6}
6868
function Welcome(props) {
6969
return <h1>Hello, {props.name}</h1>;
7070
}
7171
72-
const element = <Welcome name="Sara" />;
7372
const root = ReactDOM.createRoot(document.getElementById('root'));
73+
const element = <Welcome name="Sara" />;
7474
root.render(element);
7575
```
7676

content/docs/error-boundaries.md

Lines changed: 1 addition & 1 deletion
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/integrating-with-other-libraries.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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);
Lines changed: 1 addition & 1 deletion
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);

0 commit comments

Comments
 (0)