I am using redux to perform "CRUD" operations.
In my student.reduce.ts
file, I have this code to generate a new register:
case StudentsActionTypes.CreateStudentSucceeded:
let studentNew = [];
let s = state.students;
studentNew.push(action.student);
return {
...state,
students: studentNew,
isLoading: false,
};
The object state.students
contains the existing data and action.student
contains the new data, when I do the insert, it visually generates the new record, but I lose the old data, how can I merge state.students
and action .student
to display all data visually.
Thank you.
Try
case StudentsActionTypes.CreateStudentSucceeded:
return {
...state,
students: [...state.students, action.student],
isLoading: false,
};