Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

241
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda