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

252
Views
TypeError no capturado: no se pueden leer las propiedades de undefined (leyendo 'comentarios')

El siguiente es mi componente Dishdetail en reactjs. Recibe accesorios de su componente principal y tiene un componente secundario llamado "RenderComments" que genera los comentarios de los accesorios.

 import React from "react"; import { Card, CardImg, CardImgOverlay, CardText, CardBody, CardTitle } from "reactstrap"; function RenderDish({dish}) { if (dish != null) { return ( <Card> <CardImg width="100%" object src={dish.image} alt={dish.name}></CardImg> <CardBody> <CardTitle>{dish.name}</CardTitle> <CardText>{dish.description}</CardText> </CardBody> </Card> ) } else { return ( <div></div> ) } } function RenderComments({comments}) { let c = []; if (comments != null) { c = comments.map((element) => { return ( <li key={element.id}> <p>{element.comment}</p> <p>-- {element.author}, {new Date(element.date).toLocaleDateString("en-us", { year: "numeric", month: "short", day: "2-digit" })}</p> </li> ) }); } return ( <div> <h4>Comments</h4> <ul className="list-unstyled"> {c} </ul> </div> ) } const Dishdetail =(props)=>{ return ( <div className="container"> <div className="row"> <div className="col-xs-12 col-md-5 m-1"> <RenderDish dish={props.dish}/> </div> <div className="col-xs-12 col-md-5 m-1"> <RenderComments comments={props.dish.comments}/> </div> </div> </div> ) } export default Dishdetail;

Recibo este error: "Error de tipo no detectado: no se pueden leer las propiedades de undefined (leyendo 'comentarios')"

Como soy un principiante, no sé cómo solucionar este error. Por favor alguien me puede orientar? También me alegraría si alguien pudiera especificar el motivo de este error.

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

0

utilice el encadenamiento opcional e inspeccione por qué el comentario no está definido.

 comments?.map(() => { })
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!