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

84
Vistas
cant find the matching array of object search by id

i used a custom hook and i want to show a single item which is matched by particular id,i tried multiple method but didnt work.here is my code :

const SingleServiceDetail = () => {

const {idOfService} = useParams();
const [data] = useCustom();

const singleItem = data.find(element =>element._id === idOfService);
console.log(singleItem);
return (
    <div>
        <h2>You have Choosed :{idOfService}</h2>
        {/* <p>{singleItem.name}</p> */}
    </div>
);

};

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Possibly idOfService from useParams is a string and element._id is a number.

Try with double equal it will type coerce and check the id.

const singleItem = data.find(element => element._id == idOfService);

else change the idOfService to number

const singleItem = data.find(element => element._id === +idOfService);
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