Bird
Raised Fist0
Reactframework~20 mins

Rendering elements in React - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Rendering Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What will this React component render?
Consider this React functional component. What will it display on the screen?
React
import React from 'react';

function Greeting() {
  const name = 'Alice';
  return <h1>Hello, {name}!</h1>;
}

export default Greeting;
AHello, Alice!
BSyntax error
CHello, !
DHello, {name}!
Attempts:
2 left
💡 Hint
Look at how JSX expressions inside curly braces are evaluated.
📝 Syntax
intermediate
2:00remaining
Which option correctly renders a list of items in React?
You want to render a list of fruits using React. Which code snippet will render the list correctly without errors?
React
const fruits = ['Apple', 'Banana', 'Cherry'];

function FruitList() {
  return (
    <ul>
      {/* Fill in here */}
    </ul>
  );
}
Afruits.map(fruit => <li>{fruit}</li>)
Bfruits.forEach(fruit => <li>{fruit}</li>)
Cfruits.map(fruit => <li key={fruits.indexOf(fruit)}>{fruit}</li>)
Dfruits.map(fruit => <li key={fruit}>{fruit}</li>)
Attempts:
2 left
💡 Hint
Remember React requires a unique 'key' prop for list items.
❓ state_output
advanced
2:00remaining
What will be displayed after clicking the button twice?
Given this React component, what will the displayed count be after clicking the button two times?
React
import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  function handleClick() {
    setCount(count + 1);
    setCount(count + 1);
  }

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={handleClick}>Increase</button>
    </div>
  );
}

export default Counter;
ACount: 2
BCount: 1
CCount: 0
DCount: 3
Attempts:
2 left
💡 Hint
React batches state updates and uses the current state value in closures.
🔧 Debug
advanced
2:00remaining
Why does this React component throw an error?
This component throws an error when rendered. What is the cause?
React
import React from 'react';

function List() {
  const items = ['a', 'b', 'c'];
  return (
    <ul>
      {items.map(item => {
        <li>{item}</li>
      })}
    </ul>
  );
}

export default List;
AThe <li> elements need a unique 'key' prop to render.
BThe 'items' array is empty, so nothing renders.
CThe arrow function in map lacks a return statement, so it returns undefined.
DJSX elements must be wrapped in a fragment <>...</> inside map.
Attempts:
2 left
💡 Hint
Check how arrow functions with curly braces behave regarding return values.
🧠 Conceptual
expert
2:00remaining
What is the main reason React uses a virtual DOM?
Why does React use a virtual DOM instead of updating the real DOM directly every time?
ATo batch and minimize real DOM updates for better performance.
BTo allow React to run without a browser environment.
CTo enable server-side rendering without client-side code.
DTo store component state separately from the UI.
Attempts:
2 left
💡 Hint
Think about what makes updating the real DOM slow.

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

  1. Step 1: Understand rendering in React

    Rendering means React creates and shows elements on the screen for users to see.
  2. Step 2: Identify the correct description

    Only showing content on the screen matches rendering elements, not styling or backend tasks.
  3. Final Answer:

    Showing content on the screen using React components -> Option D
  4. 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

  1. Step 1: Recall ReactDOM.render syntax

    The correct syntax requires ReactDOM.render(element, container), where container is a DOM node.
  2. 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.
  3. Final Answer:

    ReactDOM.render(<h1>Hello</h1>, document.getElementById('root')); -> Option A
  4. Quick Check:

    ReactDOM.render(element, container) = ReactDOM.render(<h1>Hello</h1>, document.getElementById('root')); [OK]
Hint: ReactDOM.render needs element and container node [OK]
Common Mistakes:
  • Using React.render instead of ReactDOM.render
  • Passing string instead of JSX element
  • Omitting container DOM node
3. What will be displayed on the screen after running this React code?
const element = <h2>Welcome to React!</h2>;
ReactDOM.render(element, document.getElementById('root'));
medium
A. A plain text 'element' string
B. An <h2> heading with text 'Welcome to React!'
C. Nothing, because of a syntax error
D. An empty page with no content

Solution

  1. Step 1: Understand JSX element creation

    The variable 'element' holds an <h2> JSX element with text 'Welcome to React!'.
  2. Step 2: ReactDOM.render displays the element

    ReactDOM.render inserts this <h2> element inside the DOM node with id 'root', showing the heading on screen.
  3. Final Answer:

    An <h2> heading with text 'Welcome to React!' -> Option B
  4. Quick Check:

    JSX element renders as HTML heading [OK]
Hint: JSX inside render shows as HTML element [OK]
Common Mistakes:
  • Thinking JSX is a string
  • Expecting no output due to misunderstanding JSX
  • Confusing variable name with output
4. Identify the error in this React rendering code:
const element = <h1>Hello World</h1>
ReactDOM.render(element, document.getElementById('root'));
medium
A. No error, code runs correctly
B. document.getElementById('root') is undefined
C. Missing semicolon after JSX element declaration
D. JSX element must be wrapped in parentheses

Solution

  1. Step 1: Check JSX element syntax

    The JSX element is correctly assigned to 'element' variable; semicolon is optional in JavaScript.
  2. Step 2: Verify ReactDOM.render usage

    ReactDOM.render is called with valid arguments; assuming 'root' exists in HTML, no error occurs.
  3. Final Answer:

    No error, code runs correctly -> Option A
  4. Quick Check:

    Valid JSX and render call = No error, code runs correctly [OK]
Hint: JSX semicolon optional; check DOM node exists [OK]
Common Mistakes:
  • Thinking semicolon is mandatory after JSX
  • Assuming JSX needs parentheses always
  • Not verifying if 'root' element exists in HTML
5. You want to render a list of names as <li> items inside a <ul>. Which React code correctly renders this list?
const names = ['Anna', 'Bob', 'Cara'];

// Choose the correct rendering code
hard
A. ReactDOM.render(<ul><li>names</li></ul>, document.getElementById('root'));
B. const listItems = names.forEach(name => <li>{name}</li>); ReactDOM.render(<ul>{listItems}</ul>, document.getElementById('root'));
C. const listItems = names.map(name => <li key={name}>{name}</li>); ReactDOM.render(<ul>{listItems}</ul>, document.getElementById('root'));
D. const listItems = names.map(name => <li>{name}</li>); ReactDOM.render(<ul>listItems</ul>, document.getElementById('root'));

Solution

  1. Step 1: Understand list rendering with keys

    React requires keys on list items for efficient updates; map returns a new array of elements.
  2. Step 2: Analyze each option

    const listItems = names.map(name => <li key={name}>{name}</li>); ReactDOM.render(<ul>{listItems}</ul>, document.getElementById('root')); uses map with key attribute and renders list correctly. const listItems = names.forEach(name => <li>{name}</li>); ReactDOM.render(<ul>{listItems}</ul>, document.getElementById('root')); uses forEach which returns undefined. ReactDOM.render(<ul><li>names</li></ul>, document.getElementById('root')); renders literal 'names' text. const listItems = names.map(name => <li>{name}</li>); ReactDOM.render(<ul>listItems</ul>, document.getElementById('root')); misses {} around listItems, rendering literal 'listItems' text.
  3. Final Answer:

    const listItems = names.map(name => <li key={name}>{name}</li>); ReactDOM.render(<ul>{listItems}</ul>, document.getElementById('root')); -> Option C
  4. Quick Check:

    Use map with keys for lists [OK]
Hint: Use map with keys to render lists in React [OK]
Common Mistakes:
  • Using forEach instead of map for rendering
  • Omitting key attribute on list items
  • Rendering array as plain text
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard