Closed jasonwzw closed 5 years ago
src/redux/reducers/counter.js
import {INCREMENT, DECREMENT, RESET} from '../actions/counter'; const initState = { count: 0 }; export default function reducer(state = initState, action) { switch (action.type) { case INCREMENT: return { count: state.count + 1 }; case DECREMENT: return { count: state.count - 1 }; case RESET: return {count: 0}; //这里是不是应该是 return 0 default: return state } }
如果reset返回的不是0而是一个对象,console的结果会是 { counter: { count: 0 } } { counter: { count: 1 } } { counter: { count: 0 } } { counter: { count: { count: 0 } } }
webpack testRedux.js build.js 这里我这么写会报错,最后用的是 webpack testRedux.js -o build.js 是不是因为我用的webpack版本是4.16.5?所以不一样
src/redux/reducers/counter.js
如果reset返回的不是0而是一个对象,console的结果会是 { counter: { count: 0 } } { counter: { count: 1 } } { counter: { count: 0 } } { counter: { count: { count: 0 } } }
webpack testRedux.js build.js 这里我这么写会报错,最后用的是 webpack testRedux.js -o build.js 是不是因为我用的webpack版本是4.16.5?所以不一样