reduxnaming-conventionsnamingredux-actions

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


Solution

  • 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.