React · Junior · Question 46 of 75
What does createSlice generate?
- 1Only a reducer; action creators must be written by hand
- ✓Correct answer: A reducer and action creators for each case reducer
- 3A React component and a hook to display the slice's state
Explanation
createSlice({ name: 'todos', initialState, reducers: { added(state, action) {...} } }) returns todosSlice.reducer and todosSlice.actions.added with the type 'todos/added'. This removes classic Redux boilerplate with type constants and switch.