基本上,我有一个选择器,它选择将 whichCountry 设置为该值的国家和调用 Api 的日期,该日期提取该国家的日期并将其提供给应该设置日期变量的设置器。对于其余的代码,你可以去我的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>