import { createStore } from 'redux'; const store = createStore(); export default store;
const defaultState = { inputValue:"" } export default (state = defaultState,action) => { return state }
reducer必須是純函數,純函數給定輸入,固定輸出,而且不能改變輸入
//index.js作以下修改 import { createStore } from 'redux'; import reducer from './reducer' const store = createStore(reducer); export default store;
十、優化actionCreator.js,統一管理組件的actionredux
import { CHANGE_INPUT_VALUE} from './actionTypes' export const changeFocuse = (inputValue) => ({ type:CHANGE_INPUT_VALUE, inputValue });
十一、優化reducer.jsdom
import { CHANGE_INPUT_VALUE} from './actionTypes' const defaultState = { inputValue:"" } export default (state = defaultState,action) => { switch (action.type){ case CHANGE_INPUT_VALUE: const newState = JSON.parse(JSON.stringify(state)); newState.inputValue = action.inputValue; return newState; default: return state } }