Skip to content

Latest commit

 

History

History
38 lines (32 loc) · 1.07 KB

action.md

File metadata and controls

38 lines (32 loc) · 1.07 KB

Action (Redux Docs)

Actions are nothing more than an object with a type property. What makes them an action is getting dispatched by the Redux store. To use an action you'll typically need action creators.

// => actions/myFeature/creators.js
import * as t from '@/actions/types';

export const doSomething = () => ({
  type: t.DO_SOMETHING,
});

To prevent spelling errors, action types are stored in variables.

// => actions/myFeature/types.js
export const DO_SOMETHING = 'myFeature/DO_SOMETHING';

Both types and creators are being exported like this:

// => actions/index.js
export * from './myFeature';
// => actions/myFeature/index.js
export * from './creators';
// => actions/types.js
export * from './myFeature/types';

Sometimes the function instead of the resulting object is being called action. While this is not accurate, we also give in to this confusion by simply calling imported creators as actions:

// => components/MyComponent.js
import * as actions from '@/actions';