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

259
Visualizações
React Router ID dynamic routes with JSON data

i'm totally beginner in react. I tried to improve my skill day after day. Today im stuck on problem, i want to create dynamic route with JSON characters (here dragon ball z) My routes are correct but i want to show biography on only clicked characters like "i click on goku show goku bio" I want to make it without REACT HOOKS (dont useLocation, useParams ect..). At moment i'm totally stuck

Can you help me ? how can i do?

Thanks for help :)

here is the blitzstack of my project:

REACT ROUTER DBZ EXERCICE - WITHOUT HOOKS

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

0

I don't know why you are using react-router-dom and then not really use it for what it was designed for. You are working with function components, so as far as I can tell, any solution will require a React hook. Whether you just use the useParams hook to get the id to filter by, or if you declare an id state in the parent with useState, or create a React context and use both useState and useContext, or use Redux and useDispatch and useSelector. Do you see where this is headed?

I suggest just using the useParams hook as it's the most trivial to implement.

  1. Fix the character bio route so the id route match param is easier to read and consume.

    <Route path="/CharBio/:id" element={<CharBio />} />
    

    With path="/CharBio:id" the link would inject a leading : character into the id with to={`/CharBio${element.id}`}, i.e. instead of "goku" the id param would be ":goku", and this doesn't work easily for filtering.

  2. Fix the link in Perso so it's linking to a "/CharBio/:id" path.

    <Link to={`/CharBio/${element.id}`}>
      <h1>{element.id}</h1>
    </Link>
    
  3. Use the useParams hook in the CharBio component and filter the API data by id.

    export default function CharBio() {
      const { id } = useParams();
      const element = API.find(el => el.id === id);
      return element ? <p>{element.bio}</p> : null;
    }
    
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