Command Palette

Search for a command to run...

Hectal
Phase 15: State Management at Scale
React · Exercise 3 of 5 PreviousNext
Intermediate

A to-do list with Redux Toolkit

Write a todosSlice with createSlice (name todos, initial state { items: [] }) and two reducers: added(state, action) pushes { id, text: action.payload, done: false }, and toggled(state, action) flips done on the todo whose id is action.payload. Write them in the mutating style: Immer makes it safe.

Create the store with configureStore and wrap the app in <Provider store={store}>.

The input has id="new" and the button id="add". Each todo is an <li> inside <ul id="list">; clicking an <li> toggles it and gives it className="done" when done. <p id="left"> shows how many are not done, like 2 left. Don't add empty todos.

What Check tests

  1. Adding two todos shows two list items
  2. The counter says 2 left
  3. Clicking a todo marks it done
  4. Clicking it again un-marks it
  5. Empty text adds nothing
  6. Uses createSlice, configureStore and <Provider>

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.