I am trying to make an axios request but still receiving the wrong return value.
The axios method in on one file:
export const sendFormSuccessfully = data => {
let error = '';
axios.post('example url', {data})
.then(() => {
error = '';
})
.catch(reason => {
error = reason;
});
return error;
};
I am calling the method from a different file:
submittedForm = data => {
const resultSubmission = sendFormSuccessfully(data);
console.log(resultSubmission);
};
But everytime I receive an empty string. I understand it is because it is async function but I thought that because axios returns promises the value should be correct.