You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried creating a helper using createIsomorphicFn to 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:
// to be used from reactexportconstuseResourceParticipationsQuery=({
resourceId,}: {resourceId: string})=>{constqueryFn=useServerFn(getResourceParticipationsFn)returnqueryOptions({queryKey: ['resourceParticipations',resourceId],queryFn: async()=>awaitqueryFn({data: { resourceId }}),})}// to be used from loaderexportconstgetResourceParticipationsQuery=({
resourceId,}: {resourceId: string})=>{returnqueryOptions({queryKey: ['resourceParticipations',resourceId],queryFn: async()=>awaitgetResourceParticipationsFn({data: { resourceId }}),})}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
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:
Beta Was this translation helpful? Give feedback.
All reactions