Back to TIL
May 2025
posted on 05.13.2025

Remove React app from the DOM

Use ReactDOM.unmountComponentAtNode() (React < 18) or root.unmount() to remove a React app from the DOM.

import ReactDOM from 'react-dom';

const domNode = document.getElementById('root');
ReactDOM.render(<App />, domNode);

ReactDOM.unmountComponentAtNode(domNode);
import { createRoot } from 'react-dom/client';

const domNode = document.getElementById('root');
const root = createRoot(domNode);

root.render(<App />);

root.unmount();
No reactions yet

in Naperville, IL
Last visitor from Mitaka, Japan