T
TanStack•3y ago
like-gold

Query data cannot be undefined.

Hello guys, so I have this hook to return some data. the data gets fetched when i check the network tab but the useQuery is throwing some error Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ["TOP_REMIXERS"]
const getTopRemixers = async () =>
await httpClient
.get(`/admin/statistics/remixers/top`)
.then(res => res.data?.data);

export const useGetTopAnalytics = () => {
const result = useQuery([ANALYTICS.TOP_REMIXERS], getTopRemixers);

return { ...result, topRemixers: result.data };
};
const getTopRemixers = async () =>
await httpClient
.get(`/admin/statistics/remixers/top`)
.then(res => res.data?.data);

export const useGetTopAnalytics = () => {
const result = useQuery([ANALYTICS.TOP_REMIXERS], getTopRemixers);

return { ...result, topRemixers: result.data };
};
2 Replies
ambitious-aqua
ambitious-aqua•3y ago
this expression returns potentially undefined:
.then(res => res.data?.data);
.then(res => res.data?.data);
like-gold
like-goldOP•3y ago
Yes just figured. Thank you @TkDodo 🔮

Did you find this page helpful?