Menu

Day 25 of My React Learning Journey πŸš€ | Checkbox Selection and Forms
πŸ“°

Day 25 of My React Learning Journey πŸš€ | Checkbox Selection and Forms

DEV Community: reactΒ·Saravanan CnΒ·19 days ago
#E0F6EANJ
#devtoreact#devto#dev#using#learned
Reading 0:00
15s threshold

Saravanan Cn

1. Checkbox Selection Using useState

I learned how to select multiple skills using checkboxes and store the selected values in state.

What I learned:

  • useState([]) stores the selected skills in an array.
  • includes() checks whether a skill is already selected.
  • filter() removes a skill when it is unchecked.
  • The spread operator (...) adds a new skill while keeping the existing selections.

2. Handling Forms Using onSubmit

I also learned how to handle form submission in React using the onSubmit event.

What I learned:

  • `useState('') stores the input value.
  • onChange updates the name when the user types.
  • onSubmit handles the form submission.
  • event.preventDefault() prevents the browser's default form submission and page reload.` What I Learned Today

`

  • Managing checkbox selections using useState.
  • Adding and removing items from a state array.
  • Handling form inputs in React.
  • Using onSubmit to handle form submissions.
  • Using event.preventDefault() to prevent a page reload.`