DEV Community

Saravanan Cn
Saravanan Cn

Posted on

Day 25 of My React Learning Journey 🚀 | Checkbox Selection and Forms

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.`

Top comments (0)