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

babel-plugin-react-query-key-gen

v0.4.1

Published

### Problem

Readme

babel-plugin-react-query-key-gen

Problem

React Query uses the convention of a string key as a unique, readable identifier for queries. However, naming things well is difficult. Poor naming causes further confusion for the next person reading your code.

Also, query keys should include variables that your query function depends on. Query function dependencies. You will most likely be introducing stale data and bugs if you're not following this advice.

Solution

We could generate this key at build-time, inferring from the name of it's associated query function. Why name things twice when you can just reuse what's already there? This babel plugin will statically analyze your code and extract the query function name from your useQuery hooks.

Secondly, given the recommendation of using inline functions in v3, we could look at which args are being passed to the nested queryFn call, and fill in the missing keys according to that.

Installation

yarn: yarn add babel-plugin-react-query-key-gen --dev

npm: npm install babel-plugin-react-query-key-gen --dev

Then, add plugin to your .babelrc

{
  "plugins": ["babel-plugin-react-query-key-gen"]
}

Usage

You now have the option to exclude the string identifier from your query key if you want. However, if you do choose to include a string key manually, then nothing will change. This is to provide flexibility and ease of migration if you do decide to use this plugin.

This plugin makes a few assumptions about your query key order and query function:

  1. It expects your unique string key to always be the first element in your array key.
  2. If you are using inline, anonymous query functions, it will try to infer the nestted query function name and args from your function scope.
  3. If the name cannot be inferred and your unique string key is missing, a uuid will be generated for that query.
  4. If all you need is a simple string key, you can pass an empty string or empty array to the queryKey param and a key will be generated for you.
  5. Missing variables used in your nested queryFn will be added to your query keys.
  6. The same rules apply if you are using queryObjects instead of parameters. QueryObjects are actually recommended because you can omit the queryKey entirely and let the plugin do its job at build-time.