How to use the react-dom.createRoot function in react-dom

To help you get started, we’ve selected a few react-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dai-shi / react-tracked / examples / 08_comparison / src / index.ts View on Github external
import React from 'react';
import {
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
  // @ts-ignore
  createRoot,
} from 'react-dom';

import App from './App';

const ele = document.getElementById('app');
if (!ele) throw new Error('no app');
createRoot(ele).render(React.createElement(App));
github zeit / next.js / packages / next / client / index.js View on Github external
function renderReactElement(reactEl, domEl) {
  // mark start of hydrate/render
  if (SUPPORTS_PERFORMANCE_USER_TIMING) {
    performance.mark('beforeRender')
  }

  if (process.env.__NEXT_REACT_MODE !== 'legacy') {
    let callback = markRenderComplete
    if (!reactRoot) {
      const opts = { hydrate: true }
      reactRoot =
        process.env.__NEXT_REACT_MODE === 'concurrent'
          ? ReactDOM.createRoot(domEl, opts)
          : ReactDOM.createBlockingRoot(domEl, opts)
      callback = markHydrateComplete
    }
    reactRoot.render(reactEl, callback)
  } else {
    // The check for `.hydrate` is there to support React alternatives like preact
    if (isInitialRender) {
      ReactDOM.hydrate(reactEl, domEl, markHydrateComplete)
      isInitialRender = false
    } else {
      ReactDOM.render(reactEl, domEl, markRenderComplete)
    }
  }

  if (onPerfEntry && SUPPORTS_PERFORMANCE_USER_TIMING) {
    if (!(PerformanceObserver in window)) {
github dai-shi / react-hooks-fetch / examples / 04_abort / src / index.ts View on Github external
import * as React from 'react';
import {
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
  // @ts-ignore
  createRoot,
} from 'react-dom';

import App from './App';

createRoot(document.getElementById('app')).render(React.createElement(App));
github dai-shi / react-tracked / examples / 11_form / src / index.ts View on Github external
import React from 'react';
import {
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
  // @ts-ignore
  createRoot,
} from 'react-dom';

import App from './App';

const ele = document.getElementById('app');
if (!ele) throw new Error('no app');
createRoot(ele).render(React.createElement(App));
github latviancoder / hooks-by-example / src / index.js View on Github external
import React from 'react';
import ReactDOM from 'react-dom';

import './index.scss';

import App from './App';

const mode = window.localStorage.getItem('mode');
if (!mode || mode === 'sync') {
  // Synchronous
  ReactDOM.render(, document.getElementById('root'));
} else {
  // Concurrent
  ReactDOM.createRoot(document.getElementById('root')).render();
}
github dai-shi / react-hooks-fetch / examples / 01_minimal / src / index.js View on Github external
const useFetch = createUseFetch(fetchFunc, '1');

const Main = () => {
  const { result, refetch } = useFetch();
  return ;
};

const App = () => (
   <h1>{error.message}</h1>}&gt;
    Loading...}&gt;
      <main>
    
  
);

ReactDOM.createRoot(document.getElementById('app')).render();
</main>
github jxom / react-loads / examples / render-as-you-fetch / with-resources / src / index.js View on Github external
loading...}&gt;
            {movieLoaders ? (
              
            ) : (
              
            )}
          
        
      
    
  );
}

ReactDOM.createRoot(document.getElementById('root')).render();
github andrewiggins / react-suspense-sandbox / src / fiber / index.jsx View on Github external
componentDidMount() {
    spin("List.componentDidMount");
  }

  getSnapshotBeforeUpdate(prevProps, prevState) {
    spin("List.getSnapshotBeforeUpdate");
    return {};
  }

  componentDidUpdate(prevProps, prevState, snapshot) {
    spin("List.componentDidUpdate");
  }
}

const container = document.getElementById("root");
const root = ReactDOM.createRoot(container);
root.render(
  
    
    
  
);
github AndreiCalazans / react-moving-forward-example / src / index.tsx View on Github external
const render = (isConcurrent: boolean, switchConcurrency: (val: boolean) =&gt; void) =&gt; {
  const rootEl = document.getElementById('root');
  if (rootEl) {
    ReactDOM.unmountComponentAtNode(rootEl);
  }

  if (isConcurrent) {
    ReactDOM.createRoot(rootEl).render();
  } else {
    ReactDOM.render(, rootEl);
  }
};
github facebook / react / fixtures / ssr / src / index.js View on Github external
import React from 'react';
import {createRoot} from 'react-dom';

import App from './components/App';

let root = createRoot(document, {hydrate: true});
root.render();