Skip to content

Commit

Permalink
fix app rendering in older versions of wp/react
Browse files Browse the repository at this point in the history
  • Loading branch information
circlecube committed Aug 24, 2023
1 parent 526bd3a commit 256d00f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './webpack-public-path';

import App from './app';
import domReady from '@wordpress/dom-ready';
import { createRoot } from '@wordpress/element';
import {createRoot, render} from '@wordpress/element';

const WP_ADM_PAGE_ROOT_ELEMENT = 'hwa-app';
const HG_ASCI = `
Expand Down Expand Up @@ -45,10 +45,14 @@ console.log(HG_ASCI);

const HGWPRender = () => {
const DOM_ELEMENT = document.getElementById( WP_ADM_PAGE_ROOT_ELEMENT );
if ( null !== DOM_ELEMENT && 'undefined' !== typeof createRoot ) {
const root = createRoot( DOM_ELEMENT );
root.render( <App /> );
}
if (null !== DOM_ELEMENT) {
if ('undefined' !== typeof createRoot) {
// WP 6.2+ only
createRoot(DOM_ELEMENT).render(<App/>);
} else if ('undefined' !== typeof render) {
render(<App/>, DOM_ELEMENT);
}
}
};

domReady( HGWPRender );

0 comments on commit 256d00f

Please sign in to comment.