Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
import { useEffect, useRef } from 'react';
import { createRoot } from 'react-dom/client';
import { AUTH_QUERY_KEY } from 'calypso/dashboard/app/auth';
import { queryClient, persistPromise } from 'calypso/dashboard/app/query-client';
import { useSelector } from 'calypso/state';
import { getCurrentUser } from 'calypso/state/current-user/selectors';
import { useAnalyticsClient } from '../hooks/use-analytics-client';
import Layout, { router } from './layout';
import './style.scss';
export default function DashboardBackportSitesList() {
const rootInstanceRef = useRef< ReturnType< typeof createRoot > | null >( null );
const containerRef = useRef< HTMLDivElement >( null );
const user = useSelector( ( state ) => getCurrentUser( state ) );
const analyticsClient = useAnalyticsClient();
// Initialize the root instance.
useEffect( () => {
if ( ! containerRef.current || rootInstanceRef.current ) {
return;
}
rootInstanceRef.current = createRoot( containerRef.current );
return () => {
const currentRoot = rootInstanceRef.current;
if ( currentRoot ) {
currentRoot.unmount();
rootInstanceRef.current = null;
}
};
}, [] );
// Update the root instance upon dependency change.
useEffect( () => {
if ( ! rootInstanceRef.current ) {
return;
}
Promise.all( [
persistPromise,
router.preloadRoute( {
to: '/sites',
} ),
] ).then( () => {
rootInstanceRef.current?.render( <Layout analyticsClient={ analyticsClient } /> );
} );
}, [ analyticsClient ] );
// Use data already available in Redux to seed the React Query cache and avoid redundant data fetching.
useEffect( () => {
if ( user ) {
queryClient.setQueryData( AUTH_QUERY_KEY, user );
}
}, [ user ] );
return <div className="dashboard-backport-sites-list" ref={ containerRef } />;
}