Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Can't resolve `Objects are not valid as a React child` Error - reduce method as bad guy?

Rendering the below component returns

Objects are not valid as a React child

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

I could drill down the issue to this part:

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

So does the error mean that the reduce method returns an object rather than a single value? If yes, how to fix this? And if not, what else might be the issue?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Looks like you're trying to get a single value by adding it from the payroll_run_items array.

You haven't specified a start value for the accumulator, nor are you collecting the value.amount anywhere.

Here's a simple example to achieve what you want:

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda