What are Redux Toolkit slices?
Answer
A slice in Redux Toolkit is a collection of Redux reducer logic and actions for a single feature. Created with createSlice(): const counterSlice = createSlice({ name: "counter", initialState: { value: 0 }, reducers: { increment(state) { state.value += 1; }, decrement(state) { state.value -= 1; }, setAmount(state, action) { state.value = action.payload; } } });. RTK auto-generates: action creators (counterSlice.actions.increment()), action types ("counter/increment"), and the reducer function (counterSlice.reducer). The "mutating" syntax inside reducers (state.value += 1) is safe because RTK uses Immer — it detects mutations and produces a new immutable state. Use Immer-safe mutations: state.items.push(item), state.items.splice(index, 1). Add to store: configureStore({ reducer: { counter: counterSlice.reducer } }). Slices organize Redux code by feature domain rather than by type (actions folder, reducers folder).
Previous
What is the difference between Redux and React Context API?
Next
What is useSelector and useDispatch in React-Redux?