Is creating Redux thunk action and reducer that have no link to redux state and never change it an anti-pattern?

30 Views Asked by At

Could there be any rational reason to create a Redux thunk action and reducer pair for operation that seems to have zero relevance to redux state and the reducer never modifies the state, but instead just returns a copy of that state untouched. I'm relatively newbie but my current understanding, is that redux thunk and actions and reducers were designed to work with the redux state. Anyway, this stateless redux thunk code is the code I'm looking at and thinking if that is a anti-pattern solution.

Surely in the application there is plenty of other Redux thunk actions and reducers but I dont't see any problem with those as those are really working with and updating the redux state.

Basically this stateles redux thunk action seems like only a placeholder for the async operation getting a file to be downloaded by the user, and reducer is just a dummy, returning only a copy of the same state that it received.

1

There are 1 best solutions below

0
Drew Reese On

I'm inclined to say, yes, it would be a bit of an anti-pattern to create a Redux action that ultimately doesn't result in a reducer running to effect a state update in the sense that it is completely useless. If you need to run some asynchronous code/logic then just do it in an asynchronous callback function.

The purpose of Thunks is to allow Redux to handle asynchronous logic and then handle the result of it, e.g. fetched data loaded into state, "isLoading"/"isProcessing" state to conditionally render loading UI, etc. If the result isn't propagated to a reducer then it doesn't matter really what initiated the "action", and using Redux and the dispatch function is just adding unnecessary moving parts.