v1.6.0-rc.1
Pre-releaseThis 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@nextChangelog
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 newgetPendingMeta({arg, requestId})callback that can be passed as part of thecreateAsyncThunkoptions object. This is necessary because thependingaction is dispatched before the payload creator is even called.fulfilled: there is a newfulfillWithMetautility in the payload creator'sthunkApiobject, which can be used instead of returning the payload directly:return fulfillWithMeta(actualPayload, meta)rejected: the existingrejectWithValueutility now also accepts ametaargument: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
- Remove upcoming alpha.3 deprecations (#1052 - @phryneas)
- createAsyncThunk: support for
meta(#1083 - @phryneas) - Add baseQueryMeta to thunks, meta to lifecycle results (#1083 - @phryneas)
- Remove ApiWithInjectedEndpoints references (#1112 - @msutkowski)
- Add
readonlyto array-type function params (#1113 - @phryneas) - remove
Idto force lazy evaluation of API type (#1116 - @phryneas)
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)