Rendering lists of data is common in web apps, such as showing products, messages, or user profiles.
💼 Career
Understanding how to render elements dynamically is a core skill for React developers building interactive user interfaces.
Progress0 / 4 steps
1
Create the fruit array
Create a variable called fruits and assign it an array with these exact strings: "Apple", "Banana", "Cherry".
React
Hint
Use square brackets [] to create an array and separate items with commas.
2
Add a title variable
Create a variable called title and assign it the string "My Favorite Fruits".
React
Hint
Use double quotes "" to create a string.
3
Create the list items using map
Create a variable called fruitListItems and set it to the result of calling fruits.map. Inside the map, use an arrow function with parameter fruit that returns a <li> element containing the fruit.
React
Hint
Use map to transform each fruit into a list item element.
4
Render the title and list in a React component
Create a React functional component called FruitList that returns a <div> containing an <h1> with the title and an unordered list <ul> with the fruitListItems.
React
Hint
Use parentheses () to return multiple JSX elements inside the component.
Practice
(1/5)
1. What does rendering elements in React mean?
easy
A. Managing database connections
B. Writing CSS styles for components
C. Creating backend APIs
D. Showing content on the screen using React components
Solution
Step 1: Understand rendering in React
Rendering means React creates and shows elements on the screen for users to see.
Step 2: Identify the correct description
Only showing content on the screen matches rendering elements, not styling or backend tasks.
Final Answer:
Showing content on the screen using React components -> Option D
Quick Check:
Rendering = Showing content [OK]
Hint: Rendering means displaying content on screen [OK]
Common Mistakes:
Confusing rendering with styling
Thinking rendering means backend work
Mixing rendering with database tasks
2. Which of the following is the correct way to render a simple React element?
easy
A. ReactDOM.render(<h1>Hello</h1>, document.getElementById('root'));
B. React.render(<h1>Hello</h1>, 'root');
C. ReactDOM.render('Hello', document.getElementById('root'));
D. ReactDOM.render(<h1>Hello</h1>);
Solution
Step 1: Recall ReactDOM.render syntax
The correct syntax requires ReactDOM.render(element, container), where container is a DOM node.
Step 2: Check each option
ReactDOM.render(<h1>Hello</h1>, document.getElementById('root')); uses ReactDOM.render with JSX element and document.getElementById('root'), which is correct.
Final Answer:
ReactDOM.render(<h1>Hello</h1>, document.getElementById('root')); -> Option A