I’m currently working on a React project using Redux. I was putting all my actions into one file, but it quickly became unmanageable. Weirdly, I’ve had a hard time to find a nice example showing up how to split all your actions into different files. So I’m sharing how I’ve set it up, as it might help a few people out there.
I’ve divided my actions into several files:
- authActions.js
- postActions.js
- userActions.js
My actions look like this
1 2 3 4 5 |
export function getAccessToken(redirectURL, code) { return dispatch => { ... } } |
I then have a actionCreators.js files that export all actions at once.
1 2 3 |
export * from './authActions' export * from './postsActions' export * from './userActions' |
And then, I can import all actions at once:
1 |
import * as actionCreators from '../actions/actionCreators' |
But you can also import only the actions needed, of course 😉
You saved my life =) thanks a LOT.