Skip to content

Commit

Permalink
Dev helpers: Use React 18 createRoot API (#98260)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Jan 13, 2025
1 parent b071491 commit cd152fb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
7 changes: 3 additions & 4 deletions client/lib/account-settings-helper/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import languages from '@automattic/languages';
import ReactDom from 'react-dom';
import { createRoot } from 'react-dom/client';
import { useInView } from 'react-intersection-observer';
import { Provider, useDispatch, useSelector } from 'react-redux';
import QueryUserSettings from 'calypso/components/data/query-user-settings';
Expand Down Expand Up @@ -61,9 +61,8 @@ export function AccountSettingsHelper() {
);
}
export default ( element, store ) =>
ReactDom.render(
createRoot( element ).render(
<Provider store={ store }>
<AccountSettingsHelper />
</Provider>,
element
</Provider>
);
4 changes: 2 additions & 2 deletions client/lib/auth-helper/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from '@automattic/calypso-config';
import ReactDom from 'react-dom';
import { createRoot } from 'react-dom/client';

import './style.scss';

Expand Down Expand Up @@ -40,4 +40,4 @@ function AuthHelper() {
);
}

export default ( element ) => ReactDom.render( <AuthHelper />, element );
export default ( element ) => createRoot( element ).render( <AuthHelper /> );
4 changes: 2 additions & 2 deletions client/lib/features-helper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactDom from 'react-dom';
import { createRoot } from 'react-dom/client';
import FeatureList from './feature-list';

import './style.scss';
Expand All @@ -7,5 +7,5 @@ import './style.scss';
* @param element HTML Element
*/
export default function injectFeatureHelper( element ) {
ReactDom.render( <FeatureList />, element );
createRoot( element ).render( <FeatureList /> );
}
7 changes: 3 additions & 4 deletions client/lib/preferences-helper/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import ReactDom from 'react-dom';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import PreferenceList from './preference-list';

import './style.scss';

export default function injectPreferenceHelper( element, store ) {
ReactDom.render(
createRoot( element ).render(
<Provider store={ store }>
<PreferenceList />
</Provider>,
element
</Provider>
);
}
4 changes: 2 additions & 2 deletions client/lib/react-query-devtools-helper/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from '@automattic/calypso-config';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { useEffect, useState } from 'react';
import ReactDom from 'react-dom';
import { createRoot } from 'react-dom/client';
import { setStoredItem, getStoredItem } from 'calypso/lib/browser-storage';

import './style.scss';
Expand Down Expand Up @@ -59,4 +59,4 @@ function ReactQueryDevtoolsHelper() {
);
}

export default ( element ) => ReactDom.render( <ReactQueryDevtoolsHelper />, element );
export default ( element ) => createRoot( element ).render( <ReactQueryDevtoolsHelper /> );
7 changes: 3 additions & 4 deletions client/lib/store-sandbox-helper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ToggleControl } from '@wordpress/components';
import { useState, useEffect } from 'react';
import ReactDom from 'react-dom';
import { createRoot } from 'react-dom/client';
import useStoreSandboxStatusQuery from 'calypso/data/store-sandbox/use-store-sandbox-status';
import wp from 'calypso/lib/wp';

Expand Down Expand Up @@ -74,9 +74,8 @@ export function StoreSandboxHelper() {
);
}
export default ( element: HTMLElement ) =>
ReactDom.render(
createRoot( element ).render(
<QueryClientProvider client={ new QueryClient() }>
<StoreSandboxHelper />
</QueryClientProvider>,
element
</QueryClientProvider>
);

0 comments on commit cd152fb

Please sign in to comment.