I am using same form and same state in redux for add and edit. When I call api for fetching data for edit and we change our router to add form before the response arrives. All the form datas will be auto filled for add item since i am using same state for both add and edit. Is there any way to prevent this from happening?
my action creator:
fetchById: function (entity, id) {
return function (dispatch) {
dispatch(apiActions.apiRequest(entity));
return (apiUtil.fetchById(entity, id).then(function (response) {
dispatch(apiActions.apiResponse(entity));
dispatch(actions.selectItem(entity, response.body));
}
}
}
As response is late then selectItem is dispatched late. And when I open form for adding item then this form is filled with this data from response.