← React Beginner Questions - Set 2 Q11

What is the purpose of ReactDOM?

React Beginner Questions - Set 2

React builds the tree; react-dom is the package that talks to the browser and puts it on screen. Since React 18 it is also where the root lives.

Example

import { createRoot } from 'react-dom/client';
import App from './App';

const container = document.getElementById('root');

// createRoot returns a handle, not an element
const root = createRoot(container);
root.render(<App />);

// Later, to tear the whole tree down (tests, widgets, micro-frontends)
// root.unmount();

// react-dom also exposes the server entry point:
// import { renderToString } from 'react-dom/server';

What to notice

← Back to the question list