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

175
Views
Intentando ejecutar mi aplicación pero sufriendo con "No se pueden leer las propiedades de undefined (leyendo 'reducir')"

Estoy tratando de ejecutar una aplicación de transacciones, pero el error No puedo leer las propiedades de undefined (leyendo 'reducir') no me permite ejecutar la aplicación. Mi pantalla se convierte en un blanco completo por cierto. Estaba funcionando bien, y luego, de repente, boom, ya no funcionaba: ingrese la descripción de la imagen aquí

Este es mi Resumen index.tsx:

 import React, {useContext} from 'react' import incomeImg from '../../assets/income.svg' import outcomeImg from '../../assets/outcome.svg' import totalImg from '../../assets/total.svg' import { useTransactions } from '../../hooks/useTransactions' import { Container } from './styles' export function Summary() { const {transactions} = useTransactions() const summary = transactions.reduce((acc,transaction)=>{ if (transaction.type === 'deposit'){ acc.deposit += transaction.amount acc.total += transaction.amount } else { acc.withdraw = transaction.amount acc.total -= transaction.amount } return acc }, { deposit: 0, withdraw: 0, total: 0 }) return (/*SOME HTML*/)

También pongo aquí mi gancho useTransaction: https://gist.github.com/gabrielforster/314e5a5f91d8f83c78a3cc8a56a55435

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

0

Lo mejor es publicar el código para useTransactions() . Aquí supongo que en realidad está esperando que se completen algunos datos. La mejor manera de manejar esto es con un useEffect que se activa cuando transactions se actualizan y ponen summary en un estado. Agregué un control de encadenamiento opcional .? para verificar nulo o indefinido antes de usar reduce.

 const [summary, setSummary] = React.useState([]) React.useEffect(() => { setSummary(transactions?.reduce( (acc, transaction) => { if (transaction.type === 'deposit') { acc.deposit += transaction.amount; acc.total += transaction.amount; } else { acc.withdraw = transaction.amount; acc.total -= transaction.amount; } return acc; }, { deposit: 0, withdraw: 0, total: 0, }, )); }, [transactions]);
about 4 years ago · Juan Pablo Isaza Report

0

¡Fue un error en mi gancho useTransaction! gracias a todos

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!