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

151
Views
Using the useParams hook in react

I am learning useParams hook in react. I have a url like this and need to be able to extract the letter 9 from it.

    http://localhost:3010/9/solution

How can I go about this ?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Assuming you are using react-router, then you should use Browser Router in your React app: https://reacttraining.com/react-router/web/api/BrowserRouter

and then declare a route like:

<Route path="/{id}/solution" component={Component} />

and then in your Component you'll be able to use it:

const { id } = useParams();
over 4 years ago · Santiago Trujillo Report

0

I'm assuming you're using react router, if you define a route like this for example:

<Route path="/:id/about">
 <About />
</Route>

Notice that you define the path with this :id notation, that means that the id will be the param in this specific case. Then you create a Link component

<Link to="/2/about">About</Link>

And in your component that in this example is the about component you can use the hook like this:

function About() {
 const { id } = useParams();
 return (
  <div>
   <h2>Now showing post {id}</h2>
  </div>
 );
}

I have this code sandbox if you want to check the result https://codesandbox.io/s/react-router-basic-nv8pn

over 4 years ago · Santiago Trujillo 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!