Redux actions in separate file, or component file?

I feel like most actions would be component scoped and make sense to keep in the same file, similar to a function that calls setState. Is this not the right way to think about Redux though? Asking because most examples seem to have the actions moved to an actions subdirectory.

I’m answering mostly because this is the type of high-level question that asks for the experience I don’t yet have. I understand why separating out the file structure makes sense. Even if you change WHICH component can influence a given piece of state, the state management can be independent.

As a basic example, let’s say you decide that a series of checkboxes would be better served by a visual representation of a toggle switch or a 3-d representation of a push button on a control panel, The toggle, the push button, and the checkbox all implement the same action, and will dispatch the same minimum-representation of state to the store, but it’s a lot easier to organize your project by one-thing-per-file.

Also, in terms of practicality, having the action in one file and the component in another means that you can scroll through them independently in different windows of your IDE, which means that those files need to be placed somewhere, and organizing them in an “actions” directory makes sense.

1 Like