Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Desmarcando casillas para que no se envíen al servidor

Tengo algunas casillas de verificación, todas las opciones marcadas se envían al servidor como una matriz, el problema es que desmarcar no funciona, así que después de marcar una, incluso si desmarca, se envía al servidor, y si marca y desmarca varias veces se enviará el mismo valor muchas veces, aquí está el código.

 const [time, setTime] = useState([]); function handleChangeTime(e) { if (e.currentTarget.checked) { setTime([...time, e.target.value]); } else { const newArray = setTime.filter((item) => item !== e.target.value); setTime(newArray); } } console.log(time) <h4>Select the best time:</h4> <form> <label> <input type="checkbox" name="time" onChange={handleChangeTime} value="9:00" /> 9:00 am </label> <label> <input type="checkbox" name="time" onChange={handleChangeTime} value="9:30" /> 9:30 am </label> <label> <input type="checkbox" name="time" onChange={handleChangeTime} value="10:00" /> 10:00 am </label> </form>

¡Gracias a todos de antemano por la ayuda!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para actualizar el estado en función de su valor anterior, utilice el formulario de actualización funcional ...

Si el nuevo estado se calcula utilizando el estado anterior, puede pasar una función a setState . La función recibirá el valor anterior y devolverá un valor actualizado.

 function handleChangeTime({ target: { checked, value } }) { if (checked) { setTime((prev) => [...prev, value]); } else { setTime((prev) => prev.filter((item) => item !== value)); } }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!