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

142
Views
No se puede actualizar useState pasando y representando objetos

Cuando intento compilar mi archivo App.jsx, aparece el siguiente error:

Error no detectado: los objetos no son válidos como hijos de React (encontrado: objeto con claves {presente1}). Si tenía la intención de representar una colección de niños, use una matriz en su lugar.

 import React, { useState } from "react"; import Axios from "axios"; function Attendance() { const [attedanceList, setAttedanceList] = useState([]); const [attendanceMarking, setAttendanceMarking] = useState({}); Axios.get("http://localhost:9000/attendance").then((response) => { setAttedanceList(response.data.data.values); }); function changeValue(event) { let { name, value } = event.target; setAttendanceMarking((attendanceMarking) => { return { ...attendanceMarking, [name]: value }; //error here }); console.log(attendanceMarking); } function sendAllValues() { Axios.post("http://localhost:9000/attendance", { attendanceMarking }); } return ( <form> {attedanceList.map((val, index) => { if (index !== 0) { let attendance = "attendance" + index; let present = "present" + index; let absent = "absent" + index; return ( <div key={index}> <div> {val[0]} {val[1]} <input type="radio" id={present} name={attendance} value="1" checked={attendanceMarking === "1"} onChange={changeValue} /> <label for={present}>Present</label> <input type="radio" id={absent} name={attendance} value="0" checked={attendanceMarking === "0"} onChange={changeValue} /> <label for={absent}>Absent</label> </div> </div> ); } })} <button type="submit" onClick={sendAllValues}> Submit </button> </form> ); }

¿Cómo puedo renderizar objetos para poder actualizar el estado y evitar errores?

Captura de pantalla de error

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

si el valor de val[0] es React.lazy() o . React.createElement(val[0]) puede funcionar normalmente.

about 4 years ago · Santiago Gelvez 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!