Exercise: useState
by Tomas Trescak· React Fundamentals

0 / 3280 XP

Let's practice your understanding of  state management in React components using useState hook. We provide you with an incomplete ToDo pp and your goal is to add the following functionality:

  • Add a new to-do:
    • Since we did not cover forms yet, we hard-code a sample to-do item in a function and add it to the to-do list state when a button is clicked.
    • Example hard-coded item: { id: 1, text: 'Learn React', category: 'Education', isCompleted: false }
  • Mark a to-do as completed:
    • Add a button for each to-do item that toggles its isCompleted status.
  • Delete a to-do:
    • Add a button for each to-do item that removes it from the state.
  •  ⚠️ IMPORTANT: Please add role="listitem" to the element you choose to make your list element

Once again, make sure all the tests pass!

Let's practice your understanding of  state management in React components using useState hook. We provide you with an incomplete ToDo pp and your goal is to add the following functionality: * Add a new to-do: * Since we did not cover forms yet, we hard-code a sample to-do item in a function and add it to the to-do list state when a button is clicked. * Example hard-coded item: { id: 1, text: 'Learn React', category: 'Education', isCompleted: false } * Mark a to-do as completed: * Add a button for each to-do item that toggles its isCompleted status. * Delete a to-do: * Add a button for each to-do item that removes it from the state. *  ⚠️ IMPORTANT: Please add role="listitem" to the element you choose to make your list element Once again, make sure all the tests pass!

Discuss with Others
Ask questions, share your thoughts, and discuss with other learners

Join the discussion to ask questions, share your thoughts, and discuss with other learners
Loading...
Ready ...
Content Locked
This content is only available to registered users.
Please register at the the home page.
Setup
React Fundamentals
10 points
Next.js
10 points
Advanced React
Databases
10 points
React Hooks
Authentication and Authorisation
10 points
APIs
CI/CD and DevOps
Testing React
Advanced Topics