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

204
Views
El estado de mi aplicación de reacción no cambia después de hacer clic en el botón

Estoy tratando de guardar la entrada de un formulario dentro de una matriz usando useState. Creé una función para hacer clic en un botón Agregar, pero la entrada onChange no se agrega a la matriz de notas cuando hago clic en el botón. Matriz vacía en el registro de la consola. Por favor, tenga la amabilidad de señalar el problema.

 const {useState} = React; function CreateArea() { const [newNote, setNote] = useState({ title: "", content: "", }); const [notes, setNotes] = useState([]); console.log(notes); function addNote() { setNotes((prevNote) => { return [...prevNote, newNote]; }); } function handleChange(event) { const { value, name } = event.target; setNote((prevValue) => { return { ...prevValue, [name]: value, }; }); } return ( <div> <form> <input onChange={handleChange} name="title" placeholder="Title" value={newNote.newTitle} /> <textarea onChange={handleChange} name="content" placeholder="Take a note..." value={newNote.newContent} rows="3" /> <button onClick={addNote}>Add</button> </form> </div> ); } ReactDOM.render(<CreateArea />, document.getElementById("root"));
 <div id="root"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>

about 4 years ago · Juan Pablo Isaza
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!