I am trying to update a row in react table using redux logic.The following is the action that I am calling in the component.
handleEdit = () => {
this.setState({
id: this.state.id,
name: this.state.name,
uid: this.state.uid,
serial: this.state.serial,
name: this.state.name,
status: this.state.status,
nodeType: this.state.nodeType
});
this.props.editCard({
id: this.state.id,
name: this.state.name,
uid: this.state.uid,
serial: this.state.serial,
name: this.state.name,
status: this.state.status,
nodeType: this.state.nodeType
});
};
This is how I wrote the reducer
[types.CARD_UPLOADER_EDIT_SUCCESS]: (state, { payload }) => {
console.log("payload", payload);
const index =
state.data && state.data.findIndex(i => i.id === payload.id);
if (index != -1 && state.data) {
state.data.splice(index, 1, payload);
}
return { ...state, editSuccess: true };
},
Although the service was fired , instead of updation, a new entry will be added to the database. Can someone help me for sorting this out?