1

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.

ng-hobby
  • 2,077
  • 2
  • 13
  • 26
Eladerezador
  • 1,277
  • 7
  • 25
  • 48

1 Answers1

2

Try

case StudentsActionTypes.CreateStudentSucceeded:
return {
  ...state,
  students: [...state.students, action.student],
  isLoading: false,
};
MoxxiManagarm
  • 8,735
  • 3
  • 14
  • 43