Is there any deeper reason why action types in redux should be strings in all upper case with underscores?
A string is just a string, right? Why not use the the names of action creators (typically in camelCase) also as the type of the actions created by them?
capital letters for constants
It is just a convention which is common also in other other languages.
Interesting article on redux naming conventions: https://decembersoft.com/posts/a-simple-naming-convention-for-action-creators-in-redux-js/
It is mainly because of actions is being refereed from multiple modules, be it saga or react ui. It is just the convention, and gives easy readability in code. In ReactJs, actions are important focus as they are meant to change the state of the reactUI.
It is a commonly seen pattern to use constants for mutation types in various Flux implementations. This allows the code to take advantage of tooling like linters, and putting all constants in a single file allows your collaborators to get an at-a-glance view of what mutations are possible in the entire application.
Whether to use constants is largely a preference - it can be helpful in large projects with many developers, but it's totally optional if you don't like them.
Quote from Vuex which is similar to Redux but for Vue.js only.
Since constants are generally UPPER_CASE, and if you make the string the same as the contant's name, you only need one name instead of two, which makes things a little simpler.
Overall I think it is just convention and preference. And it is optional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With