Learning Redux
上QQ阅读APP看书,第一时间看更新

ES2015 - import/export

With webpack and Babel, you can import/export action creators the same way as action types. Perform the following steps:

Create a new actions.js file. First, we import the CREATE_POST action type:

import { CREATE_POST } from './actionTypes'

Then we define and export the createPost action creator:

export const createPost = (user, text) => {
return { type: CREATE_POST, user, text }
}

Finally, we can import and use the createPost action creator in the src/index.js file. Replace the whole file with the following code:

import { createPost } from './actions'

console.log(createPost('dan', 'New post'))