Skip to content

feat: return client and originalClient from createRQClient#22

Closed
Anon-136 wants to merge 3 commits intomainfrom
anon/flat-client-export
Closed

feat: return client and originalClient from createRQClient#22
Anon-136 wants to merge 3 commits intomainfrom
anon/flat-client-export

Conversation

@Anon-136
Copy link
Member

@Anon-136 Anon-136 commented Jan 15, 2026

Summary

Return client from createRQClient

  • in order to use with loader or SSR
  • with the same interface of useQuery or queryOptions like
function Comp() {
  const query = client.useQuery(
    '/users/:id',
    '$get',
    { input: { param: { id: 'none' },
  })
}

but

loader: () => {
  const result = client.client(
    '/users/:id',
    '$get',
    { input: { param: { id: 'none' },
  })
}
  • with fully-typesafe and throwOnError supported

PS. I called it FlatClientFn for now
Flat is justice 🤩

@changeset-bot
Copy link

changeset-bot bot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: 305f2d4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@softnetics/hono-react-query Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Anon-136 Anon-136 marked this pull request as ready for review January 15, 2026 09:59
@saenyakorn
Copy link
Member

To call API in loader, I highly suggest to use hono/client instead of this library. This library use hono/client internally.

Also, if you would like to use react query in server-side. Try to use "queryOptions" instead.

@SupakornNetsuwan
Copy link
Collaborator

SupakornNetsuwan commented Jan 15, 2026

async beforeLoad(){
const qc = new QueryClient()

await qc.prefetch(client.queryOptions())
},
render(){ 
const query = client.useQuery() // <-- Automatically internall grab a prefetched SSR result.

return <>...</>
}

Is something like this work?

@Anon-136
Copy link
Member Author

Anon-136 commented Jan 15, 2026

Thx for the reply
After discussing with @SupakornNetsuwan
I found ensureQueryData working

loader: async ({ context, params }) => {
  const response = await context.queryClient.ensureQueryData(
    reactQueryClient.queryOptions(
      '/appointments/:appointmentId',
      '$get',
      {
        input: {
          param: {
            appointmentId: params.appointmentId,
          },
        },
        options: { throwOnError: false },
      },
    ),
  )
  if (response.status === 404) throw notFound()
  if (response.status !== 200) throw response
},

Closing this PR

@Anon-136 Anon-136 closed this Jan 15, 2026
@Anon-136 Anon-136 deleted the anon/flat-client-export branch January 15, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants