I find your concerns very confusing.
In order:
Thunks are the most widely used middleware by a large margin [0], and we have frequently received complaints that there is no async middleware included in the Redux store by default. Thunks were in fact part of the store during the original development phase [1], but were made separate once the middleware API was defined [2]. Thunks are effectively the minimum viable way to write async logic that has access to interacting with the Redux store, so we include that in RTK out of the box to make that possible.
Sagas, observables, and other similar middleware are far too heavyweight and complex for us to endorse as the default async approach. I also strongly disagree that thunks are an "anti-pattern", and find them to be a highly useful tool (and especially so now that `async/await` syntax makes it even easier to write more complicated async logic in a readable form) [3].
You are always welcome to add another middleware or disable thunks as part of the store setup process instead if you want.
I don't see how this:
const addTodo = createAction("todos/add")
is more verbose than this:
const addTodo = (text) => {
return {
type: "todos/add",
payload: text
}
}
We've had a version of `createReducer` shown in the "Reducing Boilerplate" docs page [4] for years, and there are literally hundreds of similar "lookup table"-type utilities out there. Including this in RTK is a no-brainer. It's even more valuable, because ours uses Immer inside to let you write "mutative" immutable update logic instead of having to nest spread operators. I don't see how this is "obscuring" anything.
Finally, our recommendation is that most of the time you shouldn't even be calling `createAction` and `createReducer` yourself. Instead, you should be using the `createSlice` function [5], which automatically generates action creators and action types for you, and calls the other two functions internally.
[0] Slide 38 in https://blog.isquaredsoftware.com/2017/09/presentation-might...
[1] https://github.com/reduxjs/redux/issues/1
[2] https://github.com/reduxjs/redux/pull/63#issuecomment-110575...
[3] https://blog.isquaredsoftware.com/2017/01/idiomatic-redux-th...
[4] https://redux.js.org/recipes/reducing-boilerplate#generating...
[5] https://redux-toolkit.js.org/api/createSlice
In order:
Thunks are the most widely used middleware by a large margin [0], and we have frequently received complaints that there is no async middleware included in the Redux store by default. Thunks were in fact part of the store during the original development phase [1], but were made separate once the middleware API was defined [2]. Thunks are effectively the minimum viable way to write async logic that has access to interacting with the Redux store, so we include that in RTK out of the box to make that possible.
Sagas, observables, and other similar middleware are far too heavyweight and complex for us to endorse as the default async approach. I also strongly disagree that thunks are an "anti-pattern", and find them to be a highly useful tool (and especially so now that `async/await` syntax makes it even easier to write more complicated async logic in a readable form) [3].
You are always welcome to add another middleware or disable thunks as part of the store setup process instead if you want.
I don't see how this:
is more verbose than this: We've had a version of `createReducer` shown in the "Reducing Boilerplate" docs page [4] for years, and there are literally hundreds of similar "lookup table"-type utilities out there. Including this in RTK is a no-brainer. It's even more valuable, because ours uses Immer inside to let you write "mutative" immutable update logic instead of having to nest spread operators. I don't see how this is "obscuring" anything.Finally, our recommendation is that most of the time you shouldn't even be calling `createAction` and `createReducer` yourself. Instead, you should be using the `createSlice` function [5], which automatically generates action creators and action types for you, and calls the other two functions internally.
[0] Slide 38 in https://blog.isquaredsoftware.com/2017/09/presentation-might...
[1] https://github.com/reduxjs/redux/issues/1
[2] https://github.com/reduxjs/redux/pull/63#issuecomment-110575...
[3] https://blog.isquaredsoftware.com/2017/01/idiomatic-redux-th...
[4] https://redux.js.org/recipes/reducing-boilerplate#generating...
[5] https://redux-toolkit.js.org/api/createSlice