- 追加された行はこの色です。
- 削除された行はこの色です。
- JavaScript/React/Reducer へ行く。
- JavaScript/React/Reducer の差分を削除
#author("2021-03-19T02:19:18+09:00","default:ryuichi","ryuichi") * Reducer [#i9e14d1e] function reducer(state, action) { if (action.type === "ADD") { return { ...state, count: state.count + action.by } } else if (action.type === "MINUS") { return { ...state, count: state.count - action.by } } return state } let initialState = { count: 0 } let actions = [ { type: 'ADD', by: 2 }, { type: 'MINUS', by: 4 }, { type: 'ADD', by: 10 } ] console.log(actions.reduce(reducer, initialState))