I am writing a react front end app now, today I facing a dispatch problem. I write a edit page to edit some data, after the edit complete, I dispatch an action to send a http request to flush new data into server side database, this is the code look like:
if (!data.id) {
obj = {
type: 'punishM/addPunish',
payload: params,
};
} else {
obj = {
type: 'punishM/editPunish',
payload: {
id: data.id,
...params,
},
};
}
dispatch({
...obj,
});
after send the http request, the next step I need to refresh the UI table data to show the newest data collection by send another http request. But now the problem is that when I send the new http request to fetch data, the fetched sometimes the legacy data collection. So I need to know the first dispatch was complete, then I send the new dispatch to fetch the new data, but I did not know how to do it like this, I did not know how to listening the fisrt dispatch complete. is it possible to know the first dispath complete? or any better way to implement this?