T
TanStack10mo ago
stormy-gold

onSuccess on useQuery() --> No overload match this call

The onSuccess callback seems to be removed from last version of TanStack Query causing "No overload match this call" Error. Why ???
const { isLoading, error, data } = useQuery({
queryKey: ['myData'], // Unique key for the query
queryFn: async () => {
const response = await fetch('/api/data');
return response.json();
},
onSuccess: (data) => {
// This function will be executed when the query is successful
console.log('Data fetched successfully:', data);
// You can perform actions with the data here, like updating state or displaying a success message
},
});
const { isLoading, error, data } = useQuery({
queryKey: ['myData'], // Unique key for the query
queryFn: async () => {
const response = await fetch('/api/data');
return response.json();
},
onSuccess: (data) => {
// This function will be executed when the query is successful
console.log('Data fetched successfully:', data);
// You can perform actions with the data here, like updating state or displaying a success message
},
});
4 Replies
passive-yellow
passive-yellow10mo ago
Breaking React Query's API on purpose
Why good API design matters, even if it means breaking existing APIs in the face of resistance.
national-gold
national-gold10mo ago
What do you need the callback for ? As per Dominicks post, it's been removed. If your still having issues it might be worth reproducing what you are trying to do and explaining your use case.
stormy-gold
stormy-goldOP10mo ago
I read the TkDodo document and can understand his decision. However, it's pretty usefull to know more deeply when query succeded for certain edge cases.
national-gold
national-gold10mo ago
Yeah, you can still use the global cache callbacks for those I think

Did you find this page helpful?