-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import ReactDOM, { version as reactDomVersion } from 'react-dom'; | ||
|
||
// Uses the correct render API based on the available version of | ||
// `react-dom`. This hack can be removed when support for older | ||
// versions of React is removed. | ||
const canUseNewReactRootApi = | ||
reactDomVersion && | ||
(reactDomVersion.startsWith('18') || reactDomVersion.startsWith('0.0.0')); | ||
|
||
export const renderElement = (node, outlet) => { | ||
const root = createRoot(outlet); | ||
root.render(node); | ||
if (canUseNewReactRootApi) { | ||
// eslint-disable-next-line import/no-unresolved | ||
const { createRoot } = require('react-dom/client'); | ||
const root = createRoot(outlet); | ||
root.render(node); | ||
} else { | ||
ReactDOM.render(node, outlet); | ||
} | ||
}; |