ey dee ey em
ey dee ey em

Reputation: 8593

Best practice for naming redux action type description

Currently when using action type named as MY_ACTION_TYPE_1 = 'MY_ACTION_TYPE_1' when it gets really long, it becomes utterly unreadable as it got cut off from the view in the redux chrome extension. what is the best practice to name the value? Nature language (i.e. MY_ACTION_TYPE_1 = 'My action type 1') or should always be the same as the variable name above?

Is there any trade-offs or problem if I set the action type name value different than the action type variable name itself?

i.e. below, see the one in natural language wrap nicely, while the all cap one word method just got cut off.

enter image description here

Upvotes: 3

Views: 13655

Answers (3)

Gabriel Cecon Carlsen
Gabriel Cecon Carlsen

Reputation: 419

As long is explicity and easy to read, you are good to go.

I personally use DOMAIN_ACTION (ACTION_DOMAIN) related to @Afshin Mehrabani answer

export const UPDATE_CATEGORY = 'UPDATE_CATEGORY';
export const DELETE_CATEGORY = 'DELETE_CATEGORY';
export const GET_ALL_CATEGORIES = 'GET_ALL_CATEGORIES';

Upvotes: 0

Afshin Mehrabani
Afshin Mehrabani

Reputation: 34929

There is a brief explanation on Redux docs here:

we suggest using the "domain/action" convention for readability

https://redux.js.org/style-guide/style-guide#write-action-types-as-domaineventname

Upvotes: 7

markerikson
markerikson

Reputation: 67469

You should feel free to give your action types whatever value you find to be most maintainable and informative. Redux itself doesn't care what the values are, and doesn't even care if it's a string. You just need to make them different enough that your code can correctly determine when to update appropriate pieces of state, and informative enough that it's easy to debug your application.

Upvotes: 5

Related Questions