A reducer function in Redux Toolkit is a pure function that determines how the application's state changes in response to dispatched actions. It takes the current state and an action as arguments and returns a new state based on the action type and payload.
Reducers are pure functions — they do not mutate the original state or cause side effects.
Each reducer listens for specific action types to decide how to update the state.
Reducers return the next state based solely on the current state and the dispatched action.
In this example, each function inside the reducers field is a reducer that modifies the state based on a specific action. Redux Toolkit uses the Immer library internally, allowing you to write reducers that 'mutate' state safely.