redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

[RTK Query] api.util.upsertQueryData not work correctly when has transformResponse

Open hieuvuvan opened this issue 7 months ago • 2 comments

for example


// http GET /admin/post.json
// response json: {"post": {"id": 123, "title": "the post"}}


type Post = {
  id: number;
  title: string;
}

type PostResponse = {
  post: Post
}

export const api = createApi({
  reducerPath: "api",
  baseQuery: fetchBaseQuery(),
  endpoints: (builder) => ({
    getPost: builder.query<Post, void>({
      query: () => `/admin/post.json`,
      transformResponse: (response: PostResponse) => response.post,
      providesTags: ["post"],
    })
  })
})

// Some where in the app

const updatedPost = {
  id: 123,
  title: "My Post"
}

dispatch(api.util.upsertQueryData("getPost", updatedPost)); // this not work, undefined body dispatch

I see it is breaking change from version 2.6.0, i also comment on the commit

Image

hieuvuvan avatar Apr 11 '25 14:04 hieuvuvan