0
0
Reactframework~20 mins

JSX syntax rules in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSX Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this JSX component?
Consider this React component. What will it render in the browser?
React
function Greeting() {
  const name = "Alex";
  return <h1>Hello, {name}!</h1>;
}
AHello, Alex!
B<h1>Hello, {name}!</h1>
C<h1>Hello, Alex!</h1>
DError: JSX expressions must have one parent element
Attempts:
2 left
💡 Hint
Remember that JSX expressions inside curly braces are evaluated as JavaScript.
📝 Syntax
intermediate
2:00remaining
Which JSX snippet is syntactically correct?
Select the JSX code that will compile without syntax errors.
A<div><p>Paragraph 1</p><p>Paragraph 2</p></div></div>
B<div><p>Paragraph 1</p><p>Paragraph 2</p></div>
C<div><p>Paragraph 1</p><p>Paragraph 2</p>
D<div><p>Paragraph 1</p><p>Paragraph 2</div>
Attempts:
2 left
💡 Hint
JSX requires all tags to be properly closed and nested.
state_output
advanced
2:00remaining
What is the rendered output after clicking the button once?
Given this React component, what will be the displayed count after clicking the button once?
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>
  );
}
ACount: 1
BCount: 0
CCount: 2
DCount: 3
Attempts:
2 left
💡 Hint
Remember that React state updates may be batched and asynchronous.
🔧 Debug
advanced
2:00remaining
Which JSX code causes a syntax error?
Identify the JSX snippet that will cause a syntax error when compiled.
A<div><p>Hello</p></div>
B<input type="text" disabled />
C<img src="image.png"></img>
D<button onClick={() => alert('Hi')}>Click me</button>
Attempts:
2 left
💡 Hint
Check if all tags are properly nested and closed.
🧠 Conceptual
expert
2:00remaining
What error does this JSX code produce?
What error will this React component cause when rendered?
React
function List() {
  const items = ["a", "b", "c"];
  return (
    <ul>
      {items.map(item => <li>{item}</li>)}
    </ul>
  );
}
ANo error, renders list correctly
BSyntaxError: Unexpected token <
CTypeError: items.map is not a function
DWarning: Each child in a list should have a unique "key" prop.
Attempts:
2 left
💡 Hint
React requires a special prop when rendering lists to help identify items.