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

3 Answers

There is a brief explanation on Redux docs here:

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

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.

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';

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like