Skip to main content
edited tags; edited tags
Source Link
Yilmaz
  • 51.2k
  • 19
  • 226
  • 281

I am following the official doc to learn RTK query. But, I am not sure what is the difference between doing the cache invalidation like this

 getUsers: build.query<User[], void>({
      query: () => '/users',
      providesTags: ['User'],
    }),

and this

 providesTags: (result, error, arg) =>
        result
          ? [...result.map(({ id }) => ({ type: 'Post' as const, id })), 'Post']
          : ['Post'],

The doc explains For more granular control over the provided data, provided tags can have an associated id. This enables a distinction between 'any of a particular tag type', and 'aa specific instance of a particular tag type'. But, I have no idea what it means. Same for the invalidatesTags

I am following the official doc to learn RTK query. But, I am not sure what is the difference between doing the cache invalidation like this

 getUsers: build.query<User[], void>({
      query: () => '/users',
      providesTags: ['User'],
    }),

and this

 providesTags: (result, error, arg) =>
        result
          ? [...result.map(({ id }) => ({ type: 'Post' as const, id })), 'Post']
          : ['Post'],

The doc explains For more granular control over the provided data, provided tags can have an associated id. This enables a distinction between 'any of a particular tag type', and 'a specific instance of a particular tag type'. But, I have no idea what it means. Same for the invalidatesTags

I am following the official doc to learn RTK query. But, I am not sure what is the difference between doing the cache invalidation like this

 getUsers: build.query<User[], void>({
      query: () => '/users',
      providesTags: ['User'],
    }),

and this

 providesTags: (result, error, arg) =>
        result
          ? [...result.map(({ id }) => ({ type: 'Post' as const, id })), 'Post']
          : ['Post'],

The doc explains For more granular control over the provided data, provided tags can have an associated id. This enables a distinction between 'any of a particular tag type', and a specific instance of a particular tag type'. But, I have no idea what it means. Same for the invalidatesTags

Source Link

What are the difference in providing the tags for cache invalidation in RTK query?

I am following the official doc to learn RTK query. But, I am not sure what is the difference between doing the cache invalidation like this

 getUsers: build.query<User[], void>({
      query: () => '/users',
      providesTags: ['User'],
    }),

and this

 providesTags: (result, error, arg) =>
        result
          ? [...result.map(({ id }) => ({ type: 'Post' as const, id })), 'Post']
          : ['Post'],

The doc explains For more granular control over the provided data, provided tags can have an associated id. This enables a distinction between 'any of a particular tag type', and 'a specific instance of a particular tag type'. But, I have no idea what it means. Same for the invalidatesTags