2

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>
Maverick
  • 63
  • 6
  • this might be something related to async but not sure, also another thing to keep in mind is that the API actually return an array which I'm converting to JSON and all this works for fetching other data like infected and recovered numbers but not for this and that's what I'm not getting – Maverick May 18 '21 at 07:06
  • Btw I have commented this code on my repo and replaced it with today's date for the time being but id still like to get to the bottom fo this – Maverick May 18 '21 at 07:39

0 Answers0