当方 reduxの勉強中です。
現状コード:
import { createStore, combineReducers } from 'redux'; import uuid from 'uuid'; const addExpense = ( { description = '', note = '', amount = 0, createAt = 0 } = {} ) => ({ type: 'ADD_EXPENSE', expense: { id: uuid(), description, note, amount, createAt } }) const expensesReducerDefaultState = []; const expensesReducer = (state = expensesReducerDefaultState, action) => { switch (action.type) { case 'ADD_EXPENSE': return state.concat(action.expense); default: return state; } }; const filterReducerDefaultState = { text: '', sortBy: 'date', startDate: undefined, endDate: undefined } const filterReducer = (state = filterReducerDefaultState, action) => { switch (action.type) { default: return state; } } const store = createStore( combineReducers({ expenses: expensesReducer, filters: filterReducer }) ) store.subscribe(() => { console.log(store.getState()); }); store.dispatch(addExpense({ description: 'Rent', amount: 100 })); const demoState = { expenses: [{ id: 'dsdssdsds', description: 'jajaj dsdssd', note: 'this is final', amount: 433334, createdAt: 0 }], filters: { text: 'rent', sortBy: 'amount', startDate: undefined, endDate: undefined } };
質問:expenseReducer内にある、case 'ADD_EXPENSE'の処理ですが、returnを書かないと処理が実行されず、stateの中身が変更されません。returnを書かないと処理が実行されないとルールなどがあるのでしょうか。JSではそのようなものはなかったと思うのですが。。。 何卒よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/11 22:11
2019/06/12 01:24
2019/06/12 03:42
2019/06/12 15:09
2019/06/12 18:00
2019/06/13 04:04