createSlice
内部でcreateReducerを利用している.
code:createSlice.js
const todosSlice = createSlice({
name: 'todos',
initialState: [],
// 外部で宣言されたReducerを追加しても良い
reducers: {
todoAdded(state, action) {
state.push(action.payload);
}.
},
});
Reducerは返り値でstateを与えるかstateを変更するかができるが,どちらもやるとエラーになる.