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

ES2015 - import/export

As an added bonus of using webpack and Babel, we can put the action types in a separate actionTypes.js file and export them by performing the following steps:

Create a new actionTypes.js file and define and export the action type there:

export const CREATE_POST = 'CREATE_POST'

Then, we can import the action types that we need in other files. Replace the src/index.js file with the following code:

import { CREATE_POST } from './actionTypes'

Putting your action types in a separate file makes it very easy to figure out which actions are possible in the application—just look at the actionTypes.js file! As we are importing constants, your editor/IDE will also help by autocompleting the constant names.