This beta release updates configureStore
to remove the deprecated option of passing an array for middleware
, improves the createEntityAdapter
types to improve compatibility, updates deps to use the latest React-Redux beta, and optimizes the TS compile perf for RTKQ hooks.
npm i @reduxjs/toolkit@beta
yarn add @reduxjs/toolkit@beta
The 2.0 integration branch contains the docs preview for the 2.0 changes. Not all changes are documented yet, but you can see API reference pages for most of the new features here:
Changelog
configureStore.middleware
Option Must Be A Callback
Since the beginning, configureStore
has accepted a direct array value as the middleware
option. However, providing an array directly prevents configureStore
from calling getDefaultMiddleware(). So,
middleware: [myMiddleware]` means there is no thunk middleware added (or any of the dev-mode checks).
This is a footgun, and we've had numerous users accidentally do this and cause their apps to fail because the default middleware never got configured.
We already had made the enhancers
option only accept the callback form, so we've done the same thing for middleware
.
If for some reason you still want to replace all of the built-in middleware, do so by returning an array from the callback:
const store = configureStore({
reducer,
middleware: (getDefaultMiddleware) => {
// WARNING: this means that _none_ of the default middleware are added!
return [myMiddleware];
// or for correct TS inference, use:
// return new Tuple(myMiddleware)
}
})
But note that we consistently recommend not replacing the default middleware entirely, and that you should use return getDefaultMiddleware().concat(myMiddleware)
.
TS Updates
The types for createEntityAdapter
have been reworked for better compat with Immer drafts.
The RTK Query types for generating React hooks have been optimized for much faster TS compilation perf (~60% improvement in one synthetic example app).
Other Changes
RTK Query's custom React hooks option now checks at runtime that all 3 hooks have been provided.
A new codemod is now available as part of the @reduxjs/rtk-codemods
package that will convert a given createSlice
call to the new "create callback" notation, which is primarily used for adding thunks inside of createSlice
. Unlike the other codemods for replacing the obsolete/removed object syntax in createReducer
and createSlice
, this is purely optional.
What's Changed
- Update CI examples to use latest betas and add tests by @markerikson in #3746
- Update MSW to 1.3.2, React-Redux to 2.0-beta.0, and log Playwright by @markerikson in #3757
- Work around known TS bug with type inference by @markerikson in #3761
- Remove middleware array option by @EskiMojo14 in #3760
- warn for and migrate old options and require all hooks by @EskiMojo14 in #3549
- [RED-24] Feature/entity adapter draftable entity state by @Olesj-Bilous in #3669
- write create callback codemod by @EskiMojo14 in #3525
- Rewrite HooksWithUniqueNames type (v2.0) by @EskiMojo14 in #3767
Full Changelog: v2.0.0-beta.2...v2.0.0-beta.3