Skip to content

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

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

Open
hieuvuvan opened this issue Apr 11, 2025 · 0 comments

Comments

@hieuvuvan
Copy link

hieuvuvan commented Apr 11, 2025

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 hieuvuvan changed the title rtkq api.util.upsertQueryData not work when has transformResponse [RTK Query] api.util.upsertQueryData not work when has transformResponse Apr 11, 2025
@hieuvuvan hieuvuvan changed the title [RTK Query] api.util.upsertQueryData not work when has transformResponse [RTK Query] api.util.upsertQueryData not work correctly when has transformResponse Apr 11, 2025
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

No branches or pull requests

1 participant