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

242
Views
No se puede resolver el error `Los objetos no son válidos como un hijo de React`: ¿reducir el método como malo?

Renderizar el siguiente componente devuelve

Los objetos no son válidos como hijos de React

 import moment from "moment"; const PayrollRuns = (props) => { const runItems = props.payrollRuns.map((run) => <div key={run.id} className="flex justify-between p-2 text-lg"> <div> {moment(run.month.period).format('YYYY MMMM')}: Paid {run.payroll_run_items.length} talents </div> <div> {run.payroll_run_items.reduce((acc, value) => { return value.amount; })} </div> </div> ); return ( <div className="runs-wrapper bg-white rounded-xl h-full w-48 shadow-sx-shadow p-4 flex flex-col"> <h1 className="border-b-2 pb-4">Payroll Runs</h1> <div className="grow overflow-auto p-4">{runItems}</div> </div> ) } export default PayrollRuns

Podría profundizar el problema en esta parte:

 <div> {run.payroll_run_items.reduce((acc, value) => { return value.amount; })} </div>

Entonces, ¿el error significa que el método de reducción devuelve un objeto en lugar de un valor único? En caso afirmativo, ¿cómo solucionar esto? Y si no, ¿cuál más podría ser el problema?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que está tratando de obtener un valor único agregándolo de la matriz payroll_run_items .

No ha especificado un valor inicial para el acumulador, ni está recopilando el value.amount ninguna parte.

Aquí hay un ejemplo simple para lograr lo que quieres:

 const payroll_run_items = [{ amount: 34, // Other properties }, { amount: 35, // Other properties }] console.log(payroll_run_items.reduce((acc, value) => { return value.amount + acc; // Add 'value.amount' to 'acc' }, 0)) // Specify a start value

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!