Tom
RPC + React Query Mutations
Hi all,
When I create a react-query mutation using the hono client, if i return the json in a 200 response, the onSuccess does not populate with the right typings, it only shows overlapping keys from other response codes like 400
const $post = api.auth.signin.request.$post;
const signInRequestMutation = useMutation<
InferResponseType<typeof $post>,
Error,
InferRequestType<typeof $post>["json"]
>({
mutationFn: async (data) => {
const res = await $post({ json: data });
if (!res.ok) {
throw new Error("An error occurred");
}
// Should return:
{
success: true,
user: { //User data }
}
const response = await res.json();
return response;
},
onSuccess: (data) => {
// Only data.success is typed as its also in my 400 res
console.log(data.user)
},
onError: (error) => {
console.log(error);
},
});
32 replies