Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore nullish values in tag invalidations #4671

Conversation

pierroberto
Copy link
Contributor

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

Copy link

codesandbox bot commented Oct 19, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

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 a9def39:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

Copy link

netlify bot commented Oct 19, 2024

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit a9def39
🔍 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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@markerikson markerikson changed the title Feat/4644 tags invalidation improvements Ignore nullish values in tag invalidations Nov 23, 2024
@markerikson markerikson merged commit c87a59a into reduxjs:master Nov 23, 2024
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalidatesTags - minor improvement
2 participants