Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

axios returns "fullfilled" promise

Can someone please tell me why my Axios service function returns this:

The object looks fine in the service function.

Promise {<fulfilled>: {…}}
[[Prototype]]: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Object

Here is the call:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  useEffect(() => {
    setData(playlistService.getPlaylists);
  }, []);
  console.log(data);

And the function:

const config = {
  headers: {
    'Content-Type': 'application/json',
  },
  withCredentials: true,
};

const getPlaylists = async () => {
  try {
    const res = await axios.get(`${API_SONGS_URL}/`, config);
    console.log('RES ', res);
    return res;
  } catch (error) {
    if (error.response) {
      return error.response.data;
    }
  }
};

>Solution :

this could work

useEffect(() => {
    const fetchPlayListAsync = async () => {
        const response = await playlistService.getPlaylists();
        setData(response)
    }
   fetchPlayListAsync()
}, []);

you can add appropriate checks of fetched data

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading