Reputation: 477
I'd like to use redux-thunk
for a project I'm working on, but I don't want to rewrite my action creation functions for obvious reasons.
Is redux-thunk
smart enough to recognize that I'm not using a thunk in my dispatch? This would allow me to write new async actions without rewriting my existing actions to return a thunk.
Upvotes: 1
Views: 184
Reputation: 67449
Yes, the thunk middleware just passes through anything that is not a function (ie, plain action objects).
Note that you should be using our official Redux Toolkit package to write your logic. RTK's configureStore
automatically sets up the thunk middleware for you, and RTK's createSlice
automatically generates all those action creators based on the reducers you provide. You shouldn't ever have to write an action creator by hand, ever again.
Please see Redux Fundamentals, Part 8: Modern Redux with Redux Toolkit for examples of how RTK simplifies hand-written redux logic.
Upvotes: 4