Browse Source

Replaced old ReactDOM API with new React v18 API (#4598)

* Replaced old ReactDOM API with new React v18 API

Replaced old ReactDOM API with new React v18 API

ReactDOM.render(
  // Try changing to isLoggedIn={true}:
  <Greeting isLoggedIn={false} />,
  document.getElementById('root')
);

The above implementation has been replaced by the following implementation according to React v18. 

ReactDOM
  .createRoot(document.getElementById('root'))
  .render(<LoginControl />);

* Changed ReactDOM.createRoot syntax into two lines

```
ReactDOM
  .createRoot(document.getElementById('root'))
  .render(<LoginControl />);
```
has been changed to

```
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<LoginControl />);
```

* Added a comment on <Greeting/> comp.
main
Muhammad Yasir 3 years ago
committed by GitHub
parent
commit
2a8e0a7ab5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      content/docs/conditional-rendering.md

27
content/docs/conditional-rendering.md

@ -35,11 +35,9 @@ function Greeting(props) {
return <GuestGreeting />;
}
ReactDOM.render(
// Try changing to isLoggedIn={true}:
<Greeting isLoggedIn={false} />,
document.getElementById('root')
);
const root = ReactDOM.createRoot(document.getElementById('root'));
// Try changing to isLoggedIn={true}:
root.render(<Greeting isLoggedIn={false} />);
```
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
@ -110,10 +108,8 @@ class LoginControl extends React.Component {
}
}
ReactDOM.render(
<LoginControl />,
document.getElementById('root')
);
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<LoginControl />);
```
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
@ -140,10 +136,9 @@ function Mailbox(props) {
}
const messages = ['React', 'Re: React', 'Re:Re: React'];
ReactDOM.render(
<Mailbox unreadMessages={messages} />,
document.getElementById('root')
);
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Mailbox unreadMessages={messages} />);
```
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
@ -244,10 +239,8 @@ class Page extends React.Component {
}
}
ReactDOM.render(
<Page />,
document.getElementById('root')
);
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Page />);
```
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)

Loading…
Cancel
Save