Use React 18's New Root API Alongside the Legacy Root API

Michael Chan
InstructorMichael Chan
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 2 years ago

Utilize both React root APIs to migrate your app. We can render a portion of our app using the legacy root API (v17 compatible) and a second using the new root API (v18 exclusive). This option makes it possible to migrate portions of your app at a time.

Instructor: [0:00] One of the nice outcomes of ReactDOM shipping with two root APIs is that we can render to different parts of our page using the different root APIs. If part of our app isn't quite stable yet, with the new root API, we can migrate those selectively. Let's render to both of these roots.

[0:19] For Root 1, we'll use the new React root API, ReactDOM.createRoot from root1.render(<App />). Hit refresh in our browser. This takes a root API, so we can pass that along to keep track of these differences. To Root 2, we'll use the legacy ReactDOM.render() API, providing the component as the first argument.

[0:50] Let's save, re-render our page, update this to Root 17, not that it is 17 but that it behaves like 17. There we go.

[1:03] Because we added this one second, we can confirm through this warning message that, indeed, it is using the ReactDOM 17 legacy root API, rendering everything in that root as if it were version 17.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today