2 ms·
Thunks are hardly "weird". The thunk middleware is only about 12 lines long, and it's just a way to let you write arbitrary code that has access to `dispatch`
by acemarke 7y ago
Thunks are hardly "weird". The thunk middleware is only about 12 lines long, and it's just a way to let you write arbitrary code that has access to `dispatch` and `getState` without being tied to a specific store instance.
Thunks are our recommended standard way to write async logic in Redux apps [0], and our new official Redux Toolkit package [1] automatically sets up thunks by default as part of the store configuration.
Sagas are incredibly powerful, but most apps don't need them [2]. They're most useful when you need complex "background thread"-like behavior.
And no, Redux is definitely _not_ eliminated or replaced by hooks [3] [4].
[0] https://redux.js.org/style-guide/style-guide#use-thunks-for-async-logic https://redux.js.org/style-guide/style-guide#use-thunks-for-...
[1] https://redux-toolkit.js.org https://redux-toolkit.js.org
[2] https://redux.js.org/faq/actions#what-async-middleware-should-i-use-how-do-you-decide-between-thunks-sagas-observables-or-something-else https://redux.js.org/faq/actions#what-async-middleware-shoul...
[3] https://blog.isquaredsoftware.com/2019/03/presentation-state-of-redux/ https://blog.isquaredsoftware.com/2019/03/presentation-state...
[4] https://blog.isquaredsoftware.com/2018/03/redux-not-dead-yet/ https://blog.isquaredsoftware.com/2018/03/redux-not-dead-yet...