Skip to content

Commit 0adf680

Browse files
committed
Update createRoot examples
1 parent e1ece05 commit 0adf680

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

docs/tutorials/essentials/part-2-app-structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ root.render(
880880
)
881881
```
882882

883-
We always have to call `ReactDOM.render(<App />)` to tell React to start rendering our root `<App>` component. In order for our hooks like `useSelector` to work right, we need to use a component called `<Provider>` to pass down the Redux store behind the scenes so they can access it.
883+
We always have to call `root.render(<App />)` to tell React to start rendering our root `<App>` component. In order for our hooks like `useSelector` to work right, we need to use a component called `<Provider>` to pass down the Redux store behind the scenes so they can access it.
884884

885885
We already created our store in `app/store.js`, so we can import it here. Then, we put our `<Provider>` component around the whole `<App>`, and pass in the store: `<Provider store={store}>`.
886886

docs/tutorials/essentials/part-5-async-logic.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,14 @@ async function start() {
961961
// highlight-next-line
962962
store.dispatch(fetchUsers())
963963

964-
ReactDOM.render(
964+
const root = createRoot(document.getElementById('root')!)
965+
966+
root.render(
965967
<React.StrictMode>
966968
<Provider store={store}>
967969
<App />
968970
</Provider>
969-
</React.StrictMode>,
970-
document.getElementById('root')
971+
</React.StrictMode>
971972
)
972973
}
973974

docs/tutorials/essentials/part-8-rtk-query-advanced.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,14 @@ async function main() {
354354
// highlight-next-line
355355
store.dispatch(apiSlice.endpoints.getUsers.initiate())
356356

357-
ReactDOM.render(
357+
const root = createRoot(document.getElementById('root')!)
358+
359+
root.render(
358360
<React.StrictMode>
359361
<Provider store={store}>
360362
<App />
361363
</Provider>
362-
</React.StrictMode>,
363-
document.getElementById('root')
364+
</React.StrictMode>
364365
)
365366
}
366367
main()

docs/tutorials/fundamentals/part-3-state-actions-reducers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The Redux template for CRA comes with Redux Toolkit and React-Redux already conf
6868
- Wrap your root React component with the `<Provider>` component from React-Redux, like:
6969

7070
```jsx
71-
ReactDOM.render(
71+
root.render(
7272
<Provider store={store}>
7373
<App />
7474
</Provider>,

docs/tutorials/fundamentals/part-5-ui-and-react.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,24 +288,25 @@ Let's add that to our main `index.js` file:
288288

289289
```jsx title="src/index.js"
290290
import React from 'react'
291-
import ReactDOM from 'react-dom'
291+
import { createRoot } from 'react-dom/client'
292292
// highlight-next-line
293293
import { Provider } from 'react-redux'
294294

295295
import App from './App'
296296
import store from './store'
297297

298-
ReactDOM.render(
298+
const root = createRoot(document.getElementById('root'))
299+
300+
root.render(
299301
// highlight-start
300302
// Render a `<Provider>` around the entire `<App>`,
301303
// and pass the Redux store to it as a prop
302304
<React.StrictMode>
303305
<Provider store={store}>
304306
<App />
305307
</Provider>
306-
</React.StrictMode>,
308+
</React.StrictMode>
307309
// highlight-end
308-
document.getElementById('root')
309310
)
310311
```
311312

docs/tutorials/fundamentals/part-6-async-logic.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ For now, let's try putting this directly in `index.js`:
251251

252252
```js title="src/index.js"
253253
import React from 'react'
254-
import ReactDOM from 'react-dom'
254+
import { createRoot } from 'react-dom/client'
255255
import { Provider } from 'react-redux'
256256
import './index.css'
257257
import App from './App'
@@ -265,13 +265,14 @@ import { fetchTodos } from './features/todos/todosSlice'
265265
store.dispatch(fetchTodos)
266266
// highlight-end
267267

268-
ReactDOM.render(
268+
const root = createRoot(document.getElementById('root'))
269+
270+
root.render(
269271
<React.StrictMode>
270272
<Provider store={store}>
271273
<App />
272274
</Provider>
273-
</React.StrictMode>,
274-
document.getElementById('root')
275+
</React.StrictMode>
275276
)
276277
```
277278

docs/tutorials/quick-start.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,23 @@ Once the store is created, we can make it available to our React components by p
6262

6363
```js title="index.js"
6464
import React from 'react'
65-
import ReactDOM from 'react-dom'
65+
import { createRoot } from 'react-dom/client'
6666
import './index.css'
6767
import App from './App'
6868
// highlight-start
6969
import store from './app/store'
7070
import { Provider } from 'react-redux'
7171
// highlight-end
7272

73-
ReactDOM.render(
74-
// highlight-next-line
75-
<Provider store={store}>
76-
<App />
77-
</Provider>,
78-
document.getElementById('root')
73+
const root = createRoot(document.getElementById('root')!)
74+
75+
root.render(
76+
<React.StrictMode>
77+
// highlight-next-line
78+
<Provider store={store}>
79+
<App />
80+
</Provider>
81+
</React.StrictMode>,
7982
)
8083
```
8184

0 commit comments

Comments
 (0)