score:1

Accepted answer

testfunction is not returning a promise so you can't use then or catch and returns undefined because well, it's not returning any thing. try to return a promise like the example below however i am not sure what the dispatch argument supposed to do so i have removed it and hopefully this'll help:

export const testfunction = () => {
    return new promise((resolve, reject) => {
        otherfunction().then(( response ) => {
            //do something...
            resolve(response);
        }).catch(( error ) => {
            //do something...
            reject(error);
        });
    });
}

score:0

when you are trying to return a promise to use it in another file, you must use the following syntax:

const testfunction = () => {
    return new promise((resolve, reject) => {
        if (error) {
            return reject(error); // this is the value sent to .catch(error)
        }
        return resolve(valuetoreturn); // this is the value sent to .then(result)
    });
}

this is how you create a promise to use where you want, if it has an error it will sent to catch block, otherwise you should see the console.log(result) value.

and in your external file you can use the syntax that you are using, try it in that way to see the console.log value.

here is a link to see more information: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/promise


Related Query

More Query from same tag