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

151
Views
TypeError: no se pueden leer las propiedades de undefined (leyendo 'estado') en reaccionar

Había pasado el parámetro a otro componente a través de Link

 {props.posts.map((post)=>{ return (<> <tr > <td>{post.title}</td> <td class="pull-right" id="underline"><Link to={{pathname:"/details",state:{title:post.title}}} >Details</Link> </td> </tr> </>) })}

Pero cuando traté de extraer el valor del título en mi componente Detalles, mostró un error.
Mi Details.js es como

 import React from 'react' import { useLocation } from 'react-router-dom'; export default function Details(props) { return ( <div> <section class="section"> <br /> <section class="details"> <h4>Title:{props.location.state.title} </h4> <br /> <h4>Categories: </h4><br /> <h4>Content: </h4> </section> <br /> </section> </div> ) }

Recibí el error como

TypeError: no se pueden leer las propiedades de undefined (leyendo 'estado')

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

0

Está tratando de acceder a los datos de accesorios, mientras que ha pasado datos desde el componente Link , y no directamente al componente que se va a renderizar, para resolver este problema, puede utilizar el gancho useRouter . En primer lugar, cree una instancia de este enlace. Utilice la instancia creada para profundizar en el objeto de estado.

Si está utilizando react-router-dom v6 y superior, se realizan algunas actualizaciones sintácticas. path y state deben pasarse como accesorios separados y las propiedades del estado deben envolverse dentro de {} .

 {props.posts.map((post)=>{ return (<> <tr > <td>{post.title}</td> <td class="pull-right" id="underline"><Link to={"/details"} state={{title:post.title}}>Details</Link> </td> </tr> </>) })}

MisDetalles.js

 import React from 'react' import { useLocation } from 'react-router-dom'; export default function Details(props) { const location = useLocation() //Instance of useLocation hook. return ( <div> <section class="section"> <br /> <section class="details"> <h4>Title:{location.state.title} </h4> <br /> <h4>Categories: </h4><br /> <h4>Content: </h4> </section> <br /> </section> </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!