This bugfix release adds exported TS types for RTKQ hooks for use in wrapping logic, adds useDebugValue
to the hooks to improve display in the React DevTools, updates the inlined types for the Redux DevTools options, and fixes an issue in `createEntityAdapter that could result in duplicate IDs being stored.
Changelog
RTKQ Hook Result Types
RTK's types heavily rely on inference to minimize the amount of type info users have to provide. However, this can also make it difficult to write functions that wrap calls to RTK APIs.
Some users have asked to have types that help them write "higher-order hooks". RTK now exports types that represent "the return object for a query/mutation hook with a given value": TypedUseQueryHookResult
and TypedUseMutationResult
. Both require <ResultType, QueryArg, BaseQuery>
as generics, like this:
const baseQuery = fetchBaseQuery({url: "https://some.server"});
type CustomHookResult = TypedUseQueryHookResult<MyResultObject, MyArgObject, typeof baseQuery>
const useMyCustomHook = (arg: MyArgObject) : CustomHookResult => {
return api.useGetSomeDataQuery(arg);
}
Redux DevTools Options Fixes
As of Redux DevTools 3.0, some of field names for custom DevTools options have changed to actionsAllowlist
and actionsDenylist
. Since we inline the types instead of having a separate dependency, we've updated our TS types to match that. No runtime behavior was changed.
Other Changes
RTKQ hooks now use useDebugValue
to give a better preview of the current value in the React DevTools "Component" tab.
The <ApiProvider>
component now does a better job of registering and cleaning up focus listeners.
Fixed a bug with createEntityAdapter
that could allow duplicate IDs to be added depending on update parameters.
What's Changed
- fix: prevent duplicate ids when updating id of an element with the id of an existing element by @samatar26 in #2020
- ApiProvider: correctly register listeners, allow to disable listeners by @phryneas in #2277
- Update devtools options TS types based on RDT 3.0 by @markerikson in #2480
- fix: typo in unhandled error message by @MichielTondeur in #2538
- Use useDebugValue in useQuery and useMutation hooks by @kaankeskin in #2500
- add types for manually typing hook results in userland code by @markerikson in #2580
Full Changelog: v1.8.3...v1.8.4