Component Crafter — React

Build React components: 10 levels of props, state, effects and conditional rendering. The most effective React fundamentals game around.

What you learn in this game

Welcome, Component Maker. You'll learn React, a library for building UI. Each level shows React code and you have to predict its behavior.

Props (properties) are how a parent sends data to a child component. Props are read-only: the child can't change them.

useState stores data that can change (state). When the state changes via the setter, the component re-renders with the new value.

useEffect runs side effects (fetching data, subscribing, etc.). The dependency array controls WHEN it runs: [] = once, [dep] = when dep changes, no array = every render.

React always re-renders all children when the parent re-renders. This is by design: React prefers to re-render and rely on virtual DOM diffing for performance. React.memo() can skip a re-render if the props didn't change.

What the levels ask

  1. What's the output of this component?
  2. What does this component display?
  3. What happens after the button is clicked?
  4. What's displayed based on the condition?
  5. What's the output of this map?
  6. When does useEffect run?
  7. Two children need to share state. Who holds the state?
  8. What's the difference between these two onClick?
  9. What happens if the key is wrong?
  10. Which component re-renders?
  11. Assemble a functional component Greeting that takes a name prop and renders <p>Halo {name}</p>.
  12. Build the Counter component with an arrow function and useState so the button increments the count.

And more, 19 levels in all.