Why does the return data of a function useAsync appear undefined?

211 views Asked by At

We tried to obtain weather data, but tried with the react-async library to determine the return value of this asynchronous function. However, the status is always displayed as pending and no data is defined. Can you tell me why?


// The parameter was omitted because the required values were obtained through other functions.
const weatherData = async () => {
  let req = await axios.get(getURLs(...getTime()).curr);
  let reqData = current(req);
  // console.log(req); 
  // console.log(reqData);
  return reqData;
};


// Component function
const WeatherList = () => {
  const { data, error, isLoading, promise } = useAsync({
    promiseFn: weatherData,
  });
  console.log(data); // undefined << Why are you doing this to me?
// ... more code
}

react-async docs : https://docs.react-async.com/guide/async-components

0

There are 0 answers