Open
Description
openedon Mar 23, 2023
What problem does this address?
With WordPress 6.2, React 18 will come bundled with WordPress, and for the time being a lot of us will have to support both React 17 and 18 in our themes and plugins. It would be really nice if version
from React came bundled inside @wordpress/element
for an easier verbose check when mounting your React app.
Without version
coming from element
:
/**
* Get React version
*/
import { version } from "react";
/**
* Grab everything from @wordpress/element with a wildcard import
*/
import * as Element from "@wordpress/element";
/**
* Internal Dependencies
*/
import App from "./app";
/**
* If version is less than 18 use `render` to render the app
* otherwise use `createRoot` to render the app
*/
if (parseInt(version) < 18) {
Element.render(<App />, document.getElementById("root"));
} else {
const domNode = document.getElementById("root");
const root = Element.createRoot(domNode);
root.render(<App />);
}
What is your proposed solution?
Include version
in the import from React in @wordpress/element
Props to @ryanwelcher and @dgwyer for helping me think through this on Twitter :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment