我有一个axios调用,用于DELETE和POST我的api,并且在调用完成后并没有重新渲染。原来是因为这些调用没有返回删除或添加对象的新对象列表。为了解决这个问题,我将其放入我的代码中
删除:
case "DELETE_TRIP_REPORTS_FULFILLED": {
return {
...state,
userTripReports: state.userTripReports.filter(tripReport => tripReport !== action.response), // Filters the deleted trip report out of userTripReports
}
}
帖子:
case "POST_TRIP_REPORTS_FULFILLED": {
return {
...state,
userTripReports: state.userTripReports.reverse().concat(action.response).reverse() // The new trip report must be concatted into the first position
}
}
这是否违反任何状态可变性原则?