使用actionCreator统一创建action

1.在store文件夹下创建actionCreator,js文件
代码如下
import { CHANGE_INPUT_VALUE , ADD_TODO_ITEM , DELET_TODO_ITEM } from './ActionTypes';
export const getInputChangeAction = (value) => ({
    type: CHANGE_INPUT_VALUE,
    value
})
export const getAddItemAction = () => ({
    type : ADD_TODO_ITEM
})
export const getDeletItemAction = (index) => ({
    type : DELET_TODO_ITEM,
    index
})

2.TodoList文件中引入actionCreator
代码如下
import { getInputChangeAction , getAddItemAction , getDeletItemAction} from './store/actionCreators.js';

3.更改TodoList文件中的action
    handleChange (e) {
        const action = getInputChangeAction(e.target.value)
        store.dispatch(action);
    }
    handleAddList() {
        const action = getAddItemAction();
        store.dispatch(action)
    }
    handleDelet (index) {
        const action = getDeletItemAction(index);
        store.dispatch(action)
    }

你可能感兴趣的:(使用actionCreator统一创建action)