
上QQ阅读APP看书,第一时间看更新
Defining action creators
As we have already learned about creating action creators, doing this is left as an exercise for the reader.
Or you can simply replace the contents of the src/actions.js file with the following code:
import { CREATE_POST, EDIT_POST, SET_FILTER } from './actionTypes'
export const createPost = (user, text) => {
return { type: CREATE_POST, user, text }
}
export const editPost = (id, text) => {
return { type: EDIT_POST, id, text }
}
export const setFilter = (filter) => {
return { type: SET_FILTER, filter }
}
Then import the additional action creators we defined in the src/index.js file:
import { createPost, editPost, setFilter } from './actions'