github reduxjs/redux-toolkit v1.6.0-rc.1

pre-release3 years ago

This release candidate finalizes the upcoming RTK Query APIs. It adds new options to createAsyncThunk for adding meta fields to thunk-dispatched actions, updates the createApi lifecycle handlers to pass through those meta fields, and removes fields that were deprecated during the alpha process. We've also fleshed out the RTKQ preview docs with significant new content.

This should be the final preview before the RTK 1.6 final release, barring any unforeseen last-minute bugs. (Note: This is the same content as rc.0, but we found a bug in our build process that had wrong output in that release. Hopefully no more issues!)

The preview docs are located at https://deploy-preview-1016--redux-starter-kit-docs.netlify.app .

Installation:

npm i @reduxjs/toolkit@next

yarn add @reduxjs/toolkit@next

Changelog

Async Thunk meta Support

createAsyncThunk automatically generates action creators and action types, and then automatically dispatches those actions during execution. This simplifies the process of creating and using thunks, but like all abstractions, also limits flexibility.

One limitation has been that there was no way to customize the meta field to the actions generated by createAsyncThunk, and some users needed to add additional metadata to actions for use by other middleware.

We've updated createAsyncThunk to allow adding additional contents to meta. The approach varies based on the action type:

  • pending: there is a new getPendingMeta({arg, requestId}) callback that can be passed as part of the createAsyncThunk options object. This is necessary because the pending action is dispatched before the payload creator is even called.
  • fulfilled: there is a new fulfillWithMeta utility in the payload creator's thunkApi object, which can be used instead of returning the payload directly: return fulfillWithMeta(actualPayload, meta)
  • rejected: the existing rejectWithValue utility now also accepts a meta argument: return rejectWithValue(failedPayload, meta)

API Lifecycle meta Support

The createApi cache lifecycle callbacks like onCacheEntryAdded now make the meta field available as part of the promise result, such as cacheDataLoaded.

Code Cleanup and Types Tweaks

The fields such as onStart and onSuccess that were deprecated in earlier alphas have been removed.

The now-unused ApiWithInjectedEndpoints type was removed.

Various APIs that accept arrays were updated to mark those array parameters as readonly, to help indicate that they shouldn't be mutated, and to ensure that arrays marked as const can be accepted.

The ApiModules type was modified to prevent a inferred type of this node exceeds the maximum length the compiler will serialize TS error.

Docs Updates

We've updated to Docusaurus 2.0-beta.0, which includes Webpack 5. No visible change for you, but faster CI builds for us thanks to build artifact caching! (Our docs builds dropped from around 7 minutes each build down to around 25 seconds, thanks to only changed files being rebuilt.)

We've also completed filling out the RTK Query API docs.

Changes

Code

Docs

  • Wayyyy too many docs PRs to even try to list here :) (@Shrugsy)
  • Wayyyy too many examples moved from sandboxes to even try to list here :) (@msutkowski)
  • Match redux config for docusaurus webpack v5 (#1086 - @msutkowski)
  • Some assorted content tweaks (@markerikson)

v1.6.0-beta.0...v1.6.0-rc.1

Don't miss a new redux-toolkit release

NewReleases is sending notifications on new releases.