npm @reduxjs/toolkit 2.0.0-beta.3
v2.0.0-beta.3

latest releases: 2.2.5, 2.2.4, 2.2.3...
7 months ago

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

Full Changelog: v2.0.0-beta.2...v2.0.0-beta.3

Don't miss a new toolkit release

NewReleases is sending notifications on new releases.