Replies: 3 comments
|
The fix: call the server function directly in const userQueryOptions = (id: string) => queryOptions({
queryKey: ['user', id],
queryFn: () => fetchUser({ data: id }), // call server fn directly, no hook
})
|
|
Faced with the same problem 🙋♂️ When using |
|
You can avoid most of the duplication by making the shared export const resourceParticipationsQuery = (resourceId: string) =>
queryOptions({
queryKey: ['resourceParticipations', resourceId],
queryFn: () => getResourceParticipationsFn({ data: { resourceId } }),
})Then both the loader and |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, I'm trying to figure out how to use
queryOptionstogether withuseServerFn.I'm trying to follow the pattern of creating predefined queries and use them from react:
This works on the client, but crashes when used on the loader.
I have tried creating a helper using
createIsomorphicFnto handle both cases but it doesn't seem like it works well either.Is there a "proper" way of doing this without code duplication?
The only solution that works reliably seems to duplicate the code:
All reactions