Resetting a Slice’s State to Its Initial Value in Redux Toolkit
In Redux Toolkit, you can reset a slice’s state back to its initial value by defining a reset action inside the slice or by handling an external reset action using extraReducers.
Define a reducer (e.g., resetState) that returns the initialState directly.
Use an external shared action with extraReducers to reset multiple slices simultaneously.
Returning the initialState creates a fresh copy of the default state, ensuring immutability.