Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda