0

I am trying to get the result of the AXIOS query, in another function, but as a result I get Promise. Tell me how to get JSON?

export const get = async (url) => {
     await axios({
            method: 'get',
            url: url,
            credentials: 'include',
            mode: 'cors'
        })
            .then(response => { return response.data});
}
export const getData = async () => {
     await get('http://localhost:7070/data');
}
export const getResult= () => {
    let res = api.getData();
    return {
        type: "TEST",
        payload: res
    }
}
aleksf
  • 51
  • 4
  • 1
    Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Heretic Monkey Mar 23 '21 at 15:51
  • you need to _return_ the result of `axios(...).then(...)` from `get` function and also _return_ `get` call from `getData` function and either `await` or chain `then()` method to `api.get()` function call in `getResult`. – Yousaf Mar 23 '21 at 15:53

0 Answers0