我构建了一个应用程序并添加了CRUD功能,除了编辑功能之外,一切都运行得很好。问题是,当我试图编辑它时,它实际上命中了正确的数据库,并更新了条目,但在react应用程序中,它只是强制将所有条目更新为特定的一个条目。
更新Saga:
function* updateFeedbackSaga(action) {
try {
const updateData = yield call(api.feedback.edit, action.payload);
yield put(actions.updateFeedback(updateData));
console.log(updateData);
} catch (err) {
yield put(actions.updateFeedbackErrors(err.response.data));
}
}
编辑缩减器
import * as actionTypes from "../Actions/types";
const initialState = {
feedbacks: [],
feedback: {},
loading: false
};
export default (state = initialState, action) => {
switch (action.type) {
case actionTypes.UPDATE_FEEDBACK:
return {
...state,
feedbacks: state.feedbacks.map(
feedback =>
feedback.id === action.payload.id ? action.payload : feedback
)
};
default:
return state;
}
};
行为
//Edit and update Feedback
export const updateFeedbackRequest = newFeedbackData => ({
type: actionTypes.UPDATE_FEEDBACK_REQUEST,
payload: newFeedbackData
});
export const updateFeedback = updatedData => ({
type: actionTypes.UPDATE_FEEDBACK,
payload: updatedData
});
export const updateFeedbackErrors = errors => ({
type: actionTypes.GET_ERRORS,
payload: errors
});
这就是打印的方式
<section className = "feedback">
<div className = "employees__table" >
<h4 className = "semi-heading" > Feedback Table < /h4>
{
FeedbackList feedbacks = {feedbacks} />
}
</div>
</section >
const mapStateToProps = state => ({
feedbackList: selectors.FeedbackSelector(state)
});
这是一些图片
这是我的反馈列表

如果我编辑第一个项目,那么状态是这样的

我的反馈列表是重复编辑的反馈。我不知道我哪里做错了。
这是我的数据库

以下是工作代码:
https://codesandbox.io/s/github/montygoldy/employee-review/tree/master/client
登录: montyjatt@gmail.com密码: 12345678
https://stackoverflow.com/questions/51344805
复制相似问题