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

141
Views
Reaccionar dándome: "Error de tipo: no se pueden leer las propiedades de undefined", pero se publicará de todos modos

saltando a un proyecto de reacción para mi empresa, pero no estoy muy familiarizado con él. Tenemos un error en el que cuando un usuario publica algo, obtenemos este error, pero si actualiza, la publicación está allí de todos modos. ¿Alguna pista?

 TypeError: Cannot read properties of undefined (reading 'comment') src/Components/Main/Dispatch/DispatchDetails/DispatchDetails.tsx:1552 1549 | { dispatch.comments && 1550 | dispatch.comments.map((story, index) => 1551 | <div key={index}> > 1552 | {story.comment.split('\n').map((remark, indexRem) => { 1553 | if(remark === '') { 1554 | return <br key={indexRem} />; 1555 | } src/Components/Main/Dispatch/DispatchDetails/DispatchDetails.tsx:1550 1547 | <h3 style={boldStyle}>Dispatch Comments:</h3> 1548 | <div className="well-story"> 1549 | { dispatch.comments && > 1550 | dispatch.comments.map((story, index) => 1551 | <div key={index}> 1552 | {story.comment.split('\n').map((remark, indexRem) => { 1553 | if(remark === '') {

Código

 <div className="well-story"> { dispatch.comments && dispatch.comments.map((story, index) => <div key={index}> {story.comment.split('\n').map((remark, indexRem) => { if(remark === '') { return <br key={indexRem} />; } return <p key={indexRem} className="the-remark">{remark}</p>; }) } <p className="remark-datetime"> {story.commentBy + ' | ' + moment(story.commentDate, 'X').format('LLL')} </p> </div> ) } </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El objeto de la historia está vacío en el segundo ciclo, por lo tanto, este error estaba allí, porque el primer ciclo tenía el objeto de la historia bien, se procesó bien, pero el siguiente objeto estaba vacío, por lo tanto, mostró un error. El siguiente código debería solucionar su problema.

 <div className="well-story"> { dispatch.comments && dispatch.comments.map((story, index) => <div key={index}> {story && story.comment && story.comment.split('\n').map((remark, indexRem) => { if(remark === '') { return <br key={indexRem} />; } return <p key={indexRem} className="the-remark">{remark}</p>; }) } <p className="remark-datetime"> {story.commentBy + ' | ' + moment(story.commentDate, 'X').format('LLL')} </p> </div> ) } </div>

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!