0
0
Reactframework~20 mins

Creating first React app - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
React Beginner 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 display?
Consider this React functional component. What text will appear on the screen when it renders?
React
import React from 'react';

export default function Greeting() {
  const name = 'Alex';
  return <h1>Hello, {name}!</h1>;
}
AError: name is not defined
BHello, Alex!
CHello, name!
DHello, {name}!
Attempts:
2 left
💡 Hint
Look at how JavaScript variables are used inside JSX with curly braces.
📝 Syntax
intermediate
2:00remaining
Which option correctly defines a React functional component?
Choose the option that correctly defines a React functional component named Welcome that returns a <div> with text 'Welcome!'.
Aconst Welcome = () => <div>Welcome!</div>;
Bfunction Welcome() { return <div>Welcome!</div>; }
Cconst Welcome = () => { <div>Welcome!</div> }
Dfunction Welcome() { <div>Welcome!</div> }
Attempts:
2 left
💡 Hint
Remember that arrow functions need to return JSX explicitly or implicitly.
state_output
advanced
2:00remaining
What is the displayed count after clicking the button twice?
This React component uses state. What number will show after clicking the button two times?
React
import React, { useState } from 'react';

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

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

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>Add 2</button>
    </div>
  );
}
ACount: 3
BCount: 2
CCount: 0
DCount: 1
Attempts:
2 left
💡 Hint
Remember React state updates are asynchronous and batched.
🔧 Debug
advanced
2:00remaining
Why does this React component produce a console warning?
This component produces a console warning when rendered. What is the cause?
React
import React from 'react';

export default function List() {
  const items = ['a', 'b', 'c'];
  return (
    <ul>
      {items.map(item => <li>{item}</li>)}
    </ul>
  );
}
AMissing unique 'key' prop on list items
BArray 'items' is not defined
CJSX elements must be wrapped in a single parent element
Dmap function is not valid inside JSX
Attempts:
2 left
💡 Hint
React requires a special prop for lists to track items efficiently.
🧠 Conceptual
expert
2:00remaining
What happens if you call a React hook conditionally inside a component?
Consider this code snippet inside a React functional component:
if (someCondition) {
  const [value, setValue] = useState(0);
}
What is the result of calling a hook conditionally like this?
AReact automatically adjusts hook calls based on conditions
BThe hook works fine only when someCondition is true
CReact throws an error because hooks must be called unconditionally in the same order
DThe hook is ignored when someCondition is false, no error occurs
Attempts:
2 left
💡 Hint
Hooks rely on consistent call order between renders.