Performance: ReactDOM render process
This affects how fast React updates the UI and how smoothly the page responds to user actions.
function App() { const [count, setCount] = React.useState(0); return <Counter count={count} onClick={() => setCount(c => c + 1)} />; } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />); // React updates only changed components efficiently
ReactDOM.render(<App />, document.getElementById('root')); // Re-render entire app on every small state change outside React's control
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full ReactDOM.render on every change | Many nodes updated | Multiple reflows per update | High paint cost | [X] Bad |
| React root with selective updates | Minimal nodes updated | Single reflow per update | Low paint cost | [OK] Good |
ReactDOM.createRoot in React?App inside a DOM element with id root using React 18+?const root = ReactDOM.createRoot(document.getElementById('root'));
function Greeting() {
return <h1>Hello, React!</h1>;
}
root.render(<Greeting />);const root = ReactDOM.createRoot('root');
root.render(<App />);Dashboard inside a div with id app-root. You also want to ensure the component updates correctly when state changes. Which code snippet correctly sets up the ReactDOM render process for this scenario?Pass the test and this pattern moves unknown