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

256
Views
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 answers
Answer question

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 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!