0
0
Reactframework~20 mins

Rendering elements in React - Practice Problems & Coding Challenges

Choose your learning style9 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.