T
TanStack2y ago
correct-apricot

useQuery select usage

Hi, I'm working with the useQuery hook in React Query, and I need to extract data from it while also adding some custom logic. I want to make sure I don't disrupt the type definitions. Is it a correct approach to use the select option like this?
export const useCurrentPlan = () => {
const data = useUserConfigV2({
select: (data) => {
const isAwaitingUpgrade = getIsAwaitingUpgrade(data.current_plan);
return { currentPlan: data.current_plan, isAwaitingUpgrade };
},
});

return data;
export const useCurrentPlan = () => {
const data = useUserConfigV2({
select: (data) => {
const isAwaitingUpgrade = getIsAwaitingUpgrade(data.current_plan);
return { currentPlan: data.current_plan, isAwaitingUpgrade };
},
});

return data;
1 Reply
sensitive-blue
sensitive-blue2y ago
const { data } = useUserConfigV2
const { data } = useUserConfigV2
select only transforms data, so you still get an object back with all the meta information. data will be what you return from select

Did you find this page helpful?