entropy
entropy4w ago

useQuery different return types

Hello, I'm fetching data with useQuery and for some reason it has two different return types. In one component it returns an object with the data, error, etc properties while in the other it only returns the data. returns entry type | null | undefined
const entry = useQuery(api.functions.anime_entries.authSingleById, {
id: media._id
})
const entry = useQuery(api.functions.anime_entries.authSingleById, {
id: media._id
})
returns an object with data about the query as well
const { data: lists, error: listError } = useQuery(
api.functions.lists.authAll,
{}
)
const { data: lists, error: listError } = useQuery(
api.functions.lists.authAll,
{}
)
6 Replies
Convex Bot
Convex Bot4w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
entropy
entropyOP4w ago
Preferably it would always return the object including information on the query status. For example with entry, I want to display an error if there was a problem fetching the data. Though if there just isn't an entry yet I know to create one.
edproton
edproton4w ago
Hey @entropy can you share the queries?
entropy
entropyOP4w ago
Sure anime_entries.authSingleById
export const authSingleById = authRLSQuery({
args: { id: v.id('anime') },
handler: async (ctx, args) => {
return await ctx.db
.query('anime_entries')
.withIndex('by_animeId', q => q.eq('animeId', args.id))
.first()
}
})
export const authSingleById = authRLSQuery({
args: { id: v.id('anime') },
handler: async (ctx, args) => {
return await ctx.db
.query('anime_entries')
.withIndex('by_animeId', q => q.eq('animeId', args.id))
.first()
}
})
lists.authAll
export const authAll = authRLSQuery({
handler: async ctx => {
return await ctx.db
.query('lists')
.withIndex('by_userId', q => q.eq('userId', ctx.user._id))
.collect()
}
})
export const authAll = authRLSQuery({
handler: async ctx => {
return await ctx.db
.query('lists')
.withIndex('by_userId', q => q.eq('userId', ctx.user._id))
.collect()
}
})
ballingt
ballingt4w ago
You might be using two different useQuery functions, it's a common name for a function. There's useQuery that TanStack Query AKA React Query exports, and there's one that Convex exports. And more in other libraries!
entropy
entropyOP4w ago
Ahh that was it. One was imported from convex/react and the other from convex-helpers/react. Thanks for the help!

Did you find this page helpful?