The App function returns an <h1> element with the text 'Welcome to React!'.
Step 2: Check rendering process
The root renders the App component inside the HTML element with id 'root', so the heading will appear on the page.
Final Answer:
Welcome to React! -> Option D
Quick Check:
App returns <h1>Welcome to React!</h1> [OK]
Hint: Component returns JSX shown on page [OK]
Common Mistakes:
Thinking component name shows instead of its return
Assuming error without checking code carefully
Confusing JSX tags with plain text
4. Identify the error in this React app code:
import React from 'react';
import ReactDOM from 'react-dom/client';
function App() {
return <h1>Hello World</h1>;
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(App);
medium
A. App should be called as in render, not just App.
B. Missing import of ReactDOM.
C. Function App must return a string, not JSX.
D. document.getElementById('root') is incorrect.
Solution
Step 1: Check how render is called
React expects a JSX element or component instance in render, so is correct, not just App.
Step 2: Understand difference between component and element
App is a function, is JSX that creates an element from that function.
Final Answer:
App should be called as <App /> in render, not just App. -> Option A
Quick Check:
render needs JSX element like <App /> [OK]
Hint: Use to render component, not App alone [OK]
Common Mistakes:
Passing function name instead of JSX element to render
Confusing component function with element instance
Ignoring JSX syntax rules
5. You want to create a React app that shows a greeting message inside a div with a class container. Which code correctly creates and renders this app?