PluginProbe
TablePress – Tables in WordPress made easy / 2.4
TablePress – Tables in WordPress made easy v2.4
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
tablepress / admin / js / common / react-loader.js

react-loader.js in TablePress – Tables in WordPress made easy 2.4, at admin/js/common/react-loader.js

39 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Common functions for loading React components in TablePress JS.
3 *
4 * @package TablePress
5 * @subpackage Views JavaScript
6 * @author Tobias Bäthge
7 * @since 2.2.0
8 */
9
10 /**
11 * WordPress dependencies.
12 */
13 import { StrictMode } from 'react';
14 import { createRoot, render } from 'react-dom'; // eslint-disable-line react/no-deprecated
15
16 /**
17 * Initializes a React component on the page.
18 *
19 * @param {string} rootId HTML ID of the root element for the component.
20 * @param {Component} component JSX of the component.
21 */
22 export const initializeReactComponent = ( rootId, component ) => {
23 if ( process.env.DEVELOP ) {
24 component = <StrictMode>{ component }</StrictMode>;
25 }
26
27 const root = document.getElementById( rootId );
28 if ( root ) {
29 // Compatibility check for React 17 and 18.
30 if ( 'function' === typeof createRoot ) {
31 // React 18 (WP 6.2 and newer): Use createRoot().
32 createRoot( root ).render( component );
33 } else {
34 // React 17 (WP 6.1 and older): Use render().
35 render( component, root );
36 }
37 }
38 };
39