renderDom.tsx 870 B

123456789101112131415161718192021222324252627282930
  1. import {render} from 'react-dom';
  2. import {createRoot} from 'react-dom/client';
  3. export function renderDom(
  4. Component: React.ComponentType,
  5. container: string,
  6. props: Record<string, any> = {}
  7. ) {
  8. const rootEl = document.querySelector(container);
  9. // Note: On pages like `SetupWizard`, we will attempt to mount main App
  10. // but will fail because the DOM el wasn't found (which is intentional)
  11. if (!rootEl) {
  12. return;
  13. }
  14. // Types are for ConfigStore, the window object is from json and features is not a Set
  15. if (
  16. (window.__initialData.features as unknown as string[]).includes(
  17. 'organizations:react-concurrent-renderer-enabled'
  18. )
  19. ) {
  20. // Enable concurrent rendering
  21. const root = createRoot(rootEl);
  22. root.render(<Component {...props} />);
  23. } else {
  24. // Legacy rendering
  25. render(<Component {...props} />, rootEl);
  26. }
  27. }