What is the role of ReactDOM in a React application?
ReactDOM connects React components to the actual web page by rendering them into the browser's DOM. It acts like a bridge between React's virtual elements and the real HTML elements you see.
Click to reveal answer
beginner
What does the ReactDOM.render() function do?
ReactDOM.render() takes a React component or element and displays it inside a specified HTML element on the page. It updates the page content to match the React component's output.
Click to reveal answer
intermediate
Why does React use a virtual DOM during the render process?
React uses a virtual DOM to quickly compare changes in components without touching the real DOM often. This makes updates faster and smoother, like planning changes on paper before painting a wall.
Click to reveal answer
intermediate
What happens when ReactDOM.render() is called multiple times on the same container?
ReactDOM replaces the previous content inside the container with the new React component's output. It updates only what changed, keeping the page efficient and responsive.
Click to reveal answer
advanced
How does ReactDOM hydrate() differ from ReactDOM.render()?
ReactDOM.hydrate() is used to attach React's event handlers to existing HTML generated by server-side rendering, instead of creating new content. It helps React take over a server-rendered page smoothly.
Click to reveal answer
What is the main purpose of ReactDOM.render()?
ATo display React components inside a web page element
BTo create new React components
CTo style React components
DTo manage React state
✗ Incorrect
ReactDOM.render() shows React components inside a specified HTML element on the page.
Why does React use a virtual DOM?
ATo create new HTML tags
BTo store user data
CTo style components faster
DTo speed up updates by minimizing direct changes to the real DOM
✗ Incorrect
The virtual DOM lets React compare changes quickly and update the real DOM efficiently.
What does ReactDOM.hydrate() do?
AUpdates CSS styles
BAttaches React to existing server-rendered HTML
CRemoves React components from the page
DCreates new React components
✗ Incorrect
hydrate() connects React to HTML already rendered on the server, enabling interactivity.
If ReactDOM.render() is called twice on the same container, what happens?
AAn error occurs
BBoth components show side by side
CThe container updates to show the latest React component
DNothing changes
✗ Incorrect
ReactDOM.render() replaces the old content with the new component inside the container.
Which of these is NOT a part of the ReactDOM render process?
ADirectly modifying CSS styles
BComparing virtual DOM with real DOM
CUpdating the real DOM efficiently
DRendering React components into HTML elements
✗ Incorrect
ReactDOM render process does not directly modify CSS styles; styling is handled separately.
Explain the steps ReactDOM takes when rendering a React component into the browser.
Think about how React updates the page efficiently using virtual DOM.
You got /5 concepts.
Describe the difference between ReactDOM.render() and ReactDOM.hydrate() and when to use each.
Consider server-side rendering and client-side rendering scenarios.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of ReactDOM.createRoot in React?
easy
A. To define a new React component
B. To update the state of a component
C. To create a root container to render React components into the DOM
D. To fetch data from an API
Solution
Step 1: Understand ReactDOM.createRoot role
This function creates a root container that connects React with a specific DOM element.
Step 2: Connect React components to the DOM
Using this root, React can render components inside the chosen HTML element.
Final Answer:
To create a root container to render React components into the DOM -> Option C
Quick Check:
ReactDOM.createRoot creates root container [OK]
Hint: ReactDOM.createRoot sets where React shows content [OK]
Common Mistakes:
Confusing createRoot with component creation
Thinking it updates state
Assuming it fetches data
2. Which of the following is the correct syntax to render a React component App inside a DOM element with id root using React 18+?
easy
A. const root = ReactDOM.createRoot(document.getElementById('root')); root.render();
B. ReactDOM.render(, document.getElementById('root'));
C. ReactDOM.createRoot().render(document.getElementById('root'));
D. const root = ReactDOM.render(document.getElementById('root')); root.createRoot();
Solution
Step 1: Identify React 18+ render syntax
React 18+ uses ReactDOM.createRoot with root.render to mount components.
Step 2: Match correct method calls and parameters
const root = ReactDOM.createRoot(document.getElementById('root')); root.render(); correctly calls createRoot with the DOM element, then calls render with the component.
Final Answer:
const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />); -> Option A
We must pass document.getElementById('root') to get the actual DOM node.
Final Answer:
The argument to createRoot should be a DOM element, not a string -> Option D
Quick Check:
createRoot needs DOM element, not string [OK]
Hint: Pass DOM element, not string, to createRoot [OK]
Common Mistakes:
Passing string id instead of element
Calling render before createRoot
Thinking component type matters here
5. You want to render a React component 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?
hard
A. const root = ReactDOM.createRoot('app-root'); root.render(Dashboard);
B. const root = ReactDOM.createRoot(document.getElementById('app-root')); root.render();
C. ReactDOM.render(, document.getElementById('app-root'));
D. const root = ReactDOM.createRoot(document.querySelector('#app-root')); root.render(Dashboard());
Solution
Step 1: Select the correct DOM element
Use document.getElementById('app-root') to get the div element for rendering.
Step 2: Use ReactDOM.createRoot and root.render properly
Call createRoot with the element, then render the component as JSX (<Dashboard />) to enable React updates.
Step 3: Avoid passing string or calling component as function
Passing string or calling Dashboard() directly breaks React's rendering and update process.
Final Answer:
const root = ReactDOM.createRoot(document.getElementById('app-root')); root.render(<Dashboard />); -> Option B
Quick Check:
createRoot + render with JSX component = correct [OK]
Hint: Use createRoot on element, render JSX component for updates [OK]
Common Mistakes:
Passing string instead of element to createRoot
Using old ReactDOM.render in React 18+
Calling component as function instead of JSX
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.