redux-toolkit
redux-toolkit copied to clipboard
Feat/4644 tags invalidation improvements
Description
Closes #4644
The following public rtk query APIs now supports undefined or null tags:
- api.util.invalidateTags
- api.util.selectInvalidatedBy
- mutationDefinition.invalidateTags
Example nullish invalidate tags in mutation definition
const api = createApi({
baseQuery,
tagTypes: ['Banana'],
endpoints: (build) => ({
getBanana: build.query<unknown, number>({
query(id) {
return { url: `banana/${id}` }
},
providesTags: ['Banana'],
}),
getBananas: build.query<unknown, void>({
query() {
return { url: 'bananas' }
},
providesTags: ['Banana'],
}),
invalidateFruit: build.mutation({
query: (fruit?: 'Banana' | null) => ({ url: `invalidate/fruit/${fruit || ''}` }),
invalidatesTags(result, error, arg) {
return [arg] // arg now can also be undefined or null
}
})
}),
})
api.utils.invalidateTags
store.dispatch(api.util.invalidateTags(["Bread", params?.id]))
api.util.selectInvalidatedBy
store.dispatch(api.util.selectInvalidatedBy(["Bread", params?.id]))
Notes
Paired with @FaberVitale
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit a9def3987111bcb16e23910e173639f46c1cda41:
| Sandbox | Source |
|---|---|
| @examples-query-react/basic | Configuration |
| @examples-query-react/advanced | Configuration |
| @examples-action-listener/counter | Configuration |
| rtk-esm-cra | Configuration |
Deploy Preview for redux-starter-kit-docs ready!
| Name | Link |
|---|---|
| Latest commit | a9def3987111bcb16e23910e173639f46c1cda41 |
| Latest deploy log | https://app.netlify.com/sites/redux-starter-kit-docs/deploys/6713d317991e4a00099d0b05 |
| Deploy Preview | https://deploy-preview-4671--redux-starter-kit-docs.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.