feat: add support for React@18 in backward compatible way (#9435)
Any React version matching this semver is supported: >= 16.8 < 19 Refs #8126 Refs #8414
This commit is contained in:
25
src/core/plugins/view-legacy/index.js
Normal file
25
src/core/plugins/view-legacy/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import { getComponent } from "core/plugins/view/root-injects"
|
||||
import { render } from "./root-injects"
|
||||
|
||||
const ViewLegacyPlugin = ({ React, getSystem, getStore, getComponents }) => {
|
||||
const rootInjects = {}
|
||||
const reactMajorVersion = parseInt(React?.version, 10)
|
||||
|
||||
if (reactMajorVersion >= 16 && reactMajorVersion < 18) {
|
||||
rootInjects.render = render(
|
||||
getSystem,
|
||||
getStore,
|
||||
getComponent,
|
||||
getComponents
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
rootInjects,
|
||||
}
|
||||
}
|
||||
|
||||
export default ViewLegacyPlugin
|
||||
12
src/core/plugins/view-legacy/root-injects.jsx
Normal file
12
src/core/plugins/view-legacy/root-injects.jsx
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import React from "react"
|
||||
import ReactDOM from "react-dom"
|
||||
|
||||
export const render =
|
||||
(getSystem, getStore, getComponent, getComponents) => (domNode) => {
|
||||
const App = getComponent(getSystem, getStore, getComponents)("App", "root")
|
||||
|
||||
ReactDOM.render(<App />, domNode)
|
||||
}
|
||||
Reference in New Issue
Block a user