Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
Unable to pass Props to grand child component via Link in React 18

Parent Component (UserList Component):

const UsersList = (props) => {    
    const removeCandidateById = (id) => {
        props.removeCandidateDetails(id);
    }    
    const RenderUsersList = props.CandidateDetails.map((userDetails) => {
        return (
            <UserCard userDetails={userDetails} removeUser={removeCandidateById }  key={userDetails.id}/>
        )
}) 

From UserCard Component I would like to pass the props data to another child component via the Link state object like state: { userDetails: this.props.userDetails } , but its always undefined in the grand child component which is configured in the /userDetail path.

I tried by Functional component way also. Via Link I cant get the solution for this.

Child Component (UserCard Component) :

class UserCard extends React.Component {
  constructor(props) {
    super(props);
    const { id, name, age, occupation, phone, imgUrL } = props.userDetails;
  }
  render() {
    return (
      <Col className="col col-lg-2 mb-3 mt-4">
        <div className="card">
          <div className="card-body">
            <h5 className="card-title"> {this.name}</h5>
            <Link
              to={{
                pathname: `/userDetail/${this.id}`,
                state: { userDetails: this.props.userDetails },
              }}
            >
              <img
                className="img"
                src={avatar}
                style={this.imgStyle}
                alt="avatar"
              />
            </Link>
          </div>
        </div>
      </Col>
    );
  }
}

export default UserCard;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As you said, your version of react-router-dom is 6.3.0. In the new version you set the state for Link differently. You need to pass it to the state prop.

<Link
  to={{
    pathname: `/userDetail/${this.id}`,
  }}
  state={{ userDetails: this.props.userDetails }}
>
  <img
    className="img"
    src={avatar}
    style={this.imgStyle}
    alt="avatar"
  />
</Link>

Now, to get the access you can use the react-router-dom useLocation hook.

const { state } = useLocation();
// you have two ways to access userDetails
const { userDetails } = state // 1
const userDetails = state.userDetails // 2
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda