1

I'm new to front-end development, so maybe someone could kindly clarify the following:

In Redux, I see in all the video tutorials that actions are defined like so:

const SOME_ACTION = "SOME_ACTION"

export const someAction = () => ({
    type: SOME_ACTION
})

I wonder, what's the point of defining the SOME_ACTION constant? Why not just skip it and name the action in the function itself? For instance:

export const someAction = () => ({
    type: "SOME_ACTION"
})

What are we gaining by having a global variable that is only used within a function by the same name?

Many thanks!

Michael Seltenreich
  • 3,013
  • 2
  • 29
  • 55
  • 1
    This is a better practice of writing code. In case you have multiple reducers for the same action and want to modify the action name, you only have to make that change in one place – Tushar Shahi May 16 '22 at 04:30
  • I'm confused. As far as I can tell, the action name is always the same as the variable name. So changing the action name without changing the variable feels inconsistent, and changing the action name AND the variable name is just as much work as it would have been to just write it directly into the functions no? Maybe I'm missing something. I'm sure in a month it'll all feel very obvious to me. – Michael Seltenreich May 16 '22 at 04:34
  • 1
    Does this answer your question? https://stackoverflow.com/questions/34965856/what-is-the-point-of-the-constants-in-redux – Lin Du May 19 '22 at 04:02

0 Answers0