React Native Axios Call Inside Function

I tried to put POST by AXIOS function inside another function to reuse it multiple times. but unfortunately It doesn't work as I expected (which was working using FETCH),


export async function post(apiRoute, body) {

    try {

        body = JSON.stringify(body);, body, httpOptions)
                console.log(;                // I have data here
    catch (err) {
        return err;

And the caller is:

    async DoLogin(userName, password) {
        var data = await post(url,{     // post is axios method defined above in another file
            UserName: userName,
            Password: password

        return data;                // I have nothing here

And the problem is I got undefined in DoLogin but got data inside POST method, It seems the problem is related to timing, axions returns a promise which is not possible to read in DoLogin, how I can do this? I did this via FETCH and it works perfectly.

Read more here:

Content Attribution

This content was originally published by Mertez at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: