OpenAPI-Qraft / openapi-qraft

Generate a type-safe TanStack Query React ✨ client from your OpenAPI document
https://openapi-qraft.github.io/openapi-qraft/
MIT License
29 stars 3 forks source link

typed hook callbacks #200

Open lkarcol opened 5 hours ago

lkarcol commented 5 hours ago

Hello,

version: 2.0.0-next.12

callback parameters are not more typed ? (data,variables)

const { mutateAsync: updateAppearance } =
   apiClient.page.updatePage.useMutation({
      onSuccess(data, variables, context) {
    },
});

This works

updateAppearance({},{
    onSuccess(data, variables, context) {
    },
  });
radist2s commented 5 hours ago

@lkarcol, thank you for the question. <service>.<operatiom>.useMutation(...) hook requires a first argument to be a predefined parameter, or undefined. In your case, you could use:

const { mutateAsync: updateAppearance } =
   apiClient.page.updatePage.useMutation(undefined, {
    onSuccess(data, variables, context) {
      // ...
    },
});

updateAppearance({...}, {
  onSuccess(data, variables, context) {
    // ...
  },
});
lkarcol commented 4 hours ago

@radist2s Thanks for response,

this is how I used it in version 1.x, but for some reason it doesn't work for me now.

is it possible that I did the migration to v 2.x wrong?

radist2s commented 1 hour ago

@lkarcol, did you apply codemode to the migration?