Reputation: 8593
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.
Upvotes: 3
Views: 13655
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
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
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