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

155
Views
How to convert id data which i recieve using useParams to only number

JsonData

[
{
      "id": "2",
      "name": "Ajay",
      "role": "Employee",
      "department": "Accounts Department",
      "ratings": "4",
      "joiningdate": "2 Jan 2021"
}
]

This is the App

<React.Fragment>
      <Routes>
        <Route path="/employee/:id" element={<Employee />} />
      </Routes>
</React.Fragment>

Inside employee component i am using

let empId=useParams()

i get empID but its in this format {id:"2"}

what changes should i do to make only 2 so that i can to pass in api req as below

axios
      .get(`http://localhost:8000/EmployeeData/${empId}`)
      .then((res) => {
        console.log(res.data);
      })
      .catch((err) => {
        console.log(err);
      });
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Convert the id to number Number(res.data.id) Number("123")

about 4 years ago · Juan Pablo Isaza Report

0

You can destructure object from useParams:

const {id:empId} = useParams();

or you can simply use dot notation in get()

.get(`http://localhost:8000/EmployeeData/${empId.id}`)
about 4 years ago · Juan Pablo Isaza Report

0

The data type of empId is an object so you can get the id with empId.id

Please find the reference here

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!