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>
);
};
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);