Our code currently has a function that calls a toast message popup while saving an object to the database.
export function addAnimal(animalObject) {
return function(dispatch) {
showToastNotification(() => {
return addAnimal(animalObject);
}, dispatch);
};
}
function showToastNotification(handleToastSave, dispatch) {
return handleToastSave()
.then(() => {
showMessage("this was a success")(dispatch);
})
.catch(() => {
showMessage("Something went wrong!")(dispatch);
})
.finally(() => {
saveMode(false)(dispatch);
});
}
My question is I want to pass a message string as a parameter to the showToastNotification like this:
export function addAnimal(animalObject) {
return function(dispatch) {
showToastNotification(("successfully added animal") => {
return addAnimal(animalObject);
}, dispatch);
};
}
function showToastNotification(message, handleToastSave, dispatch) {
return handleToastSave()
.then(() => {
showMessage(message)(dispatch);
})
.catch(() => {
showMessage("Something went wrong!")(dispatch);
})
.finally(() => {
saveMode(false)(dispatch);
});
}
This doesn't work. I'm not super familiar with how the fat arrow in this function works. Would it be possible to pass a prop to showToastNotification?