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

201
Visualizações
How to pass props within components with react-router v6

I'm struggling to pass props between components with react-rouer v6

Here is the routes in App.tsx, I want to pass props from the component (Home) which redirect to this one (EditUser)

<Routes>
    <Route path={ROUTES.HOME} element={<Home />} />
    <Route path={ROUTES.EDIT_USER} element={<EditUser props />} />
</Routes>

The home page have some functionality to render a table with users

Here is the function to navigate to the EditUser page to be able to edit
I want to be able to pass one of the users once the button "edit" is clicked (I added the state since I read that was the way to acces from the Edit User page)

  const handleEdit = (user: IUser) => {
    navigate(ROUTES.EDIT_USER, {
      state: {
        user,
      },
    });
  };

The edit button (Redirection is working It's just the fact to pass that user from components)

<EditButton
   data-testid={`edit-button-${user.id}`}
   text={ES.common.edit}
   onClick={() => {
      handleEdit(user);
   }}
   ></EditButton>

Any idea?

As always, thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When you send state in the route transition it isn't sent via props, but rather it's sent via the routing context. In the EditUser component you can access the sent route state via the location object returned from the useLocation hook.

Example:

import { useLocation } from 'react-router-dom';

...

const location = useLocation();
const { state } = location;
const { user } = state || {};
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