Basically, I have a picker that picks the country upon which whichCountry is set to that value and the date Api is called which extracts the date of that country and gives it to the setter which is supposed to set the date variable to that. for the rest of the code, you can go to my repo
const [date, setDate] = useState("");
const fetchDate = useCallback(async () => {
const data = await fetch(
"https://api.apify.com/v2/key-value-stores/tVaYRsPHLjNdNBu7S/records/LATEST?disableRedirect=true"
);
const jsonDatad = await data.json();
// jsArray= [...jsonData];
console.log(jsonDatad[1]["country"]);
jsonDatad.forEach((element) => {
setDate(() => {
console.log(element["country"], whichCountry);
if (element["country"] == whichCountry) {
console.log(typeof element["lastUpdatedApify"]);
return (element["lastUpdatedApify"]);
}
});
console.log(date+"in")
});
},[whichCountry]);
useEffect(() => {
fetchDate();
}, [whichCountry]);
<Stat_card
count={infected}
date={date?date:"data unavailable"}
desc="Total infections"
txtcol="red.400"
img="https://image.flaticon.com/icons/png/128/2659/2659980.png"
tag="Infected"
></Stat_card>