Home / Learn React / Practice Challenges

Practice Challenges

Write the code, press Check my answer and see which rules pass. 12 auto-checked challenges from beginner to advanced.

In shortEach challenge runs your code in the browser and checks the result like a user would.

Beginner

Show a greetingAuto-checked

Goal: Make App show an h1 that says Hello, React! and a paragraph below it.

  • An h1 says Hello, React!
  • A p element exists
Props: a Badge componentAuto-checked

Goal: Create a Badge component that shows its label prop in a span. Use it twice in App with the labels New and Sale.

  • Two span elements
  • One says New
  • One says Sale
Render a listAuto-checked

Goal: Show the fruits array as a ul with one li per fruit. Do not forget key.

  • Three list items
  • Mango is listed
  • No key warning in the console
A counterAuto-checked

Goal: Make a button that shows Count: 0 and increases by one on every click.

  • Starts at 0
  • Goes to 2 after two clicks
Show and hideAuto-checked

Goal: A button Toggle shows or hides a paragraph with the id secret. It starts hidden (not in the DOM).

  • Hidden at start
  • Visible after one click
  • Hidden after two clicks

Intermediate

Controlled inputAuto-checked

Goal: Type in the input and show Hello, NAME in a paragraph. The input must be controlled.

  • The paragraph follows the input
  • Input shows the typed value
Add to a listAuto-checked

Goal: Typing in the input and clicking Add appends an li and clears the input.

  • Adds first item
  • Adds a second item
  • Clears the input
Delete from a listAuto-checked

Goal: Each item has a Delete button that removes only that item.

  • Starts with 3
  • Deleting the first button leaves b and c
Derived valueAuto-checked

Goal: Show the number of characters typed in a span with id len. Do not store it in state.

  • Shows 0 at start
  • Shows 5 after typing hello
Load rows from the APIAuto-checked

Goal: The fake api("GET") returns { ok, data }. Load the notes when App mounts and show each title in an li. Show Loading... in a p until the data arrives.

  • Shows Loading first
  • Two li after loading
  • Titles are shown
Create a row with POSTAuto-checked

Goal: Add a form with an input #t and a button. On submit call api("POST", { title }), add the returned row to the list and clear the input. The list must load first, like before.

  • Has input #t and a form
  • New note appears
  • Input is cleared

Advanced

useEffect timerAuto-checked

Goal: Make #sec count up by one every 100 ms (this demo is fast). Clean up the timer.

  • Starts at 0
  • Has increased after half a second
useReducer counterAuto-checked

Goal: Use useReducer with the actions inc, dec and reset. Buttons have the texts +, - and Reset.

  • + twice gives 2
  • - gives 1
  • Reset gives 0
Custom hook useToggleAuto-checked

Goal: Write a custom hook useToggle(initial) that returns [value, toggle] and use it for a button that switches between ON and OFF.

  • Starts as OFF
  • Click gives ON
  • Source defines useToggle
Delete a row with DELETEAuto-checked

Goal: Every li needs a button with class del. Clicking it calls api("DELETE", { id }) and removes the row from the list only after the call succeeds.

  • One delete button per row
  • Clicking removes that row
  • The right row stays