I am using immer to manage my redux state. It has an item which is an array of customers. There is a delete button on my website and on the delete button, I want to delete the item from the array in the list of customers in my state. In this example, I want to delete Id 100
Redux State
customers : [{Id: "100", Name: "John"},{Id: "200", Name: "Mark"}],
address: null,
randomStuff [{}]
Code
customerIdToBeDeleted = 100
const newCustomers = produce(customers, (draft) => {
const newCustomers = draft.filter((x) => x.Id !== customerIdToBeDeleted );
draft = newCustomers ;
});
This does not work. It says cannot reassign the parameter draft. How can I remove one Id from the array and store that in the state?