Angular 10 - Insert data using Redux

68 views Asked by At

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.

1

There are 1 answers

0
MoxxiManagarm On BEST ANSWER

Try

case StudentsActionTypes.CreateStudentSucceeded:
return {
  ...state,
  students: [...state.students, action.student],
  isLoading: false,
};