npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reno-stack/hono-react-query

v0.0.3

Published

A utility library for using Hono with React Query

Readme

@reno-stack/hono-react-query

A utility library for integrating Hono RPC endpoints with React Query in your React applications.

Features

  • Type-safe: Leverages Hono and React Query types for full type safety.
  • Simple API: Easily create query and mutation options from your Hono endpoints.

Installation

npm install @reno-stack/hono-react-query
pnpm install @reno-stack/hono-react-query
yarn add @reno-stack/hono-react-query

Usage

React Query has a feature called QueryOptions which is basically for creating reusable queryFn and queryKeys. By taking advantage of this. This utility gives you two functions called createHonoQueryOptions and createHonoMutationOptions. Here's how you'd use them:

For each route of our application, we'll create a {route}.queries.ts under a folder named queries in our web application (these naming conventions are arbitrary and can be changed to anything that you'd like)

Let's say we have a notes route and we want to create a query and a mutation for it. In notes.queries.ts, you would have something like this:

import { client } from "../utils/hono-client";

import {
  createHonoMutationOptions,
  createHonoQueryOptions,
} from "@reno-stack/hono-react-query";

export const notesQueryOptions = createHonoQueryOptions(
  ["notes"],
  client.notes.$get
);

export const noteByIdQueryOptions = createHonoQueryOptions(
  ({ param: { id } }) => ["notes", id],
  client.notes[":id"].$get
);

export const createNoteMutationOptions = createHonoMutationOptions(
  client.notes.$post
);

We only need to pass the endpoint returned from our Hono RPC's client and the rest is handled by the utility. This utility takes cares of the problems mentioned above and here's how we would use them:

Queries

For an endpoint that doesn't take any parameters, you can just do:

const notesQuery = useQuery(notesQueryOptions());

Simple as that! and when it's time to invalidate any of these queries, you could do something like:

await queryClient.invalidateQueries({
  queryKey: notesQueryOptions().queryKey,
});

However if your endpoint takes parameters, you can do:

const noteByIdQuery = useQuery(
  noteByIdQueryOptions({ param: { id } }, { enabled: !!id })
);

As you can see, the first argument (which is required) is the parameters for the endpoint and the second argument is the options for the query.

Mutations

Here's how you'd use the createNoteMutationOptions function defined earlier:

const createNoteMutation = useMutation(createNoteMutationOptions());

And when it's time for mutating, you can do:

createNoteMutation.mutate({ title: "New Note", content: "This is a new note" });

Note: By default, this utility prioritizes the json property for the body of the request. If your endpoint doesn't have a json property, you can pass whatever is in the body of the request as the first argument. However, let's say your endpoint takes a form property, then you can do:

createNoteMutation.mutate({
  form: { title: "New Note", content: "This is a new note" },
});

What problem does this utility solve?

Let's say we have a notes router and we want to use Hono RPC alongside React Query, this is the simplest approach that could get us started:

const notesQuery = useQuery({
  queryKey: ["notes"],
  queryFn: () => client.notes.$get(),
});

Simple enough, right? Except the fetch API (which Hono RPC uses under the hood) doesn't handle errors by default, so we'd need some sort of fetch wrapper that takes care of errors, okay...

// Let's say you made a general purpose and type-safe wrapper around fetch
const fetchWrapper = (endpoint: ...) => {...}

const  notesQuery = useQuery({
queryKey: ["notes"],
queryFn: () => fetchWrapper(client.notes.$get)
});

Now this may seem like it's fully type-safe, but it can get annoying. What if some of our endpoints occasionally return errors? We'd have to do something like InferResponseType<typeof client.notes.$get, 200> to get the success payload type. Not to mention you'd have to do the same for mutations and their error types.

This will result in a lot of repetition in the long run, fetchWrapper is repeated every time and perhaps the worst of all, our queryKey is a magical array. If we want to invalidate it somewhere else, we have no safe way of accessing it, unless we create a central file for keeping the keys.

As explained above in the Usage section, this utility solves all of these problems by providing a simple and type-safe API.