I've looked around threads like this one, but it doesn't seem to help with my rather bizare issue.
Here are the 3 relevant methods.
const createFormData = post => {
const {
title,
body,
image
} = post;
const data = new FormData();
data.append(
"body",
JSON.stringify({
title,
body,
mediaType: image.type
})
);
console.log(data); // prints
return data;
};
const submitMedia = (data, replace) => async dispatch => {
console.log('reached'); // never prints
dispatch({
type: SUBMITTING
});
try {
const response = await axios.post(
`http://${GATEWAY}:5000/api/uploads/single`,
data
);
dispatch({
type: SUBMISSION_PENDING
});
replace("NewSubmission", {
name: "NewSubmission"
});
} catch (err) {
// TODO test this
dispatch({
type: SUBMISSION_FAIL,
payload: err.response.data
});
alert("Uh oh", "Something went wrong");
console.log("Error caught", err);
}
};
const handleSubmit = async () => {
try {
const post = {
title,
body,
image
};
const data = createFormData(post);
console.log('reached'); // never prints
submitMedia(data, replace);
} catch (err) {
console.log("err caught --> ", err);
}
};
My program seems to build the form data properly, but it's almost as if it never exits createFormData(post)
method. Not sure here to go from here, I've tried wrapping the method as a closure as this answer suggests, but no dice. I've even tried moving the async out of handleSubmit()
, still nothing. Not sure what I'm doing wrong.