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.
Beginner
Goal: Make App show an h1 that says Hello, React! and a paragraph below it.
- An h1 says Hello, React!
- A p element exists
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
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
Goal: Make a button that shows Count: 0 and increases by one on every click.
- Starts at 0
- Goes to 2 after two clicks
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
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
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
Goal: Each item has a Delete button that removes only that item.
- Starts with 3
- Deleting the first button leaves b and c
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
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
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
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
Goal: Use useReducer with the actions inc, dec and reset. Buttons have the texts +, - and Reset.
- + twice gives 2
- - gives 1
- Reset gives 0
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
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