T
TanStack3y ago
ratty-blush

Exposing refetch from Provider: How to type it properly?

How do you type the returnType of refetch when you expose it from a Provider? ex.
const {
isLoading,
data,
refetch,
} = useQuery(
["user", user],
() => someApi()
{
enabled: !!user,
select: ({ user }) => ({
a: user?.a,
b: user?.b,
}),
}
);


return (
<Provider value={{ refetch }}>{children}</Provider>
)
const {
isLoading,
data,
refetch,
} = useQuery(
["user", user],
() => someApi()
{
enabled: !!user,
select: ({ user }) => ({
a: user?.a,
b: user?.b,
}),
}
);


return (
<Provider value={{ refetch }}>{children}</Provider>
)
1 Reply
wise-white
wise-white3y ago
I think this is probably the idiomatic way to do it:
UseQueryResult["refetch"]
UseQueryResult["refetch"]
You could do it in a few other ways but considering there's no specific type/interface exported for refetch (as far as I can see), I'd probably go with the above.

Did you find this page helpful?