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

135
Views
¿Cómo puedo restablecer mi campo de entrada después de enviar el formulario en ReactJS?

Intenté establecer el estado en una cadena vacía pero no funciona, el valor ingresado se restablece pero aún muestra el valor ingresado dentro del campo de entrada. ¿Cómo puedo arreglar esto?

 import { useState } from 'react'; const App = () => { const [task,setTask] = useState(''); const [list,setList] = useState([]); const submitHandler = (event) => { event.preventDefault(); const newTask = { id: new Date().getTime().toString(), title: task }; setList([...list, newTask]); setTask(''); } const clearList = () => { setList([]); } const removeItem = (id) => { const filteredList = list.filter(item => item.id !== id); setList(filteredList); } return <div> <h2>To do list!</h2> <form onSubmit={submitHandler}> Enter Task! <input type='text' placeholder='Wut you upto?' onChange = {(event) => {setTask(event.target.value)}}> </input> </form> <div> {list.map((obj) => ( <h4 key={obj.id}>{obj.title}<button onClick={() => removeItem(obj.id)}>X</button></h4>))} <button onClick={clearList}>Clear All</button> </div> </div> } export default App
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

necesita agregar un atributo de value al campo de entrada:

 <input type='text' placeholder='Wut you upto?' onChange = {(event) => {setTask(event.target.value)}}> value={task} </input>
about 4 years ago · Juan Pablo Isaza 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!