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

react-zustand-query

v1.1.1

Published

This is the data fetching and caching library with zustand

Readme

react-zustand-query

A lightweight data fetching and caching library for React, inspired by React Query and built on top of Zustand. It provides hooks for data fetching, caching, and mutations with a simple API and full TypeScript support.

For a detailed list of changes and updates, see the CHANGELOG.

Read the docs →

Features

  • Simple and minimal API
  • Query and mutation hooks: useQuery, useMutation, useInfiniteQuery
  • Automatic retries with exponential backoff
  • Infinite query support for pagination
  • Query client for cache management
  • Full TypeScript support

Installation

npm install react-zustand-query

or

yarn add react-zustand-query

Usage

1. Setup QueryClient (optional)

import { QueryClient } from "react-zustand-query";

// Create a query client instance (optional, only if you want to manage cache directly)
const queryClient = new QueryClient();

// Access query state by key
const userQueryState = queryClient.getState("user");

2. useQuery Example

import { useQuery } from "react-zustand-query";

function fetchUser() {
  return fetch("https://jsonplaceholder.typicode.com/users/1").then((res) =>
    res.json()
  );
}

const { data, isLoading, error } = useQuery({
  queryKey: "user",
  queryFn: fetchUser,
});

3. useMutation Example

import { useMutation } from "react-zustand-query";

function addTodo(newTodo) {
  return fetch("/api/todos", {
    method: "POST",
    body: JSON.stringify(newTodo),
    headers: { "Content-Type": "application/json" },
  }).then((res) => res.json());
}

const { mutate, data, error, isLoading } = useMutation({
  mutationFn: addTodo,
  onSuccess: () => {
    // handle success
  },
  onError: () => {
    // handle error
  },
});

// Usage in a component:
// mutate({ title: "New Todo" });

4. useInfiniteQuery Example

import { useInfiniteQuery } from "react-zustand-query";

function fetchPosts({ pageParam = 0 }) {
  return fetch(`/api/posts?page=${pageParam}&limit=10`).then((res) =>
    res.json()
  );
}

const {
  data,
  isLoading,
  error,
  fetchNextPage,
  hasNextPage,
  isFetchingNextPage,
} = useInfiniteQuery({
  queryKey: ["posts"],
  queryFn: fetchPosts,
  getNextPageParam: (lastPage, allPages, lastPageParam) => {
    // Return null/undefined to indicate no more pages
    return lastPage.hasMore ? lastPageParam + 1 : null;
  },
  initialPageParam: 0,
});

// Access the data
const allPosts = data?.pages.flatMap((page) => page.posts) ?? [];

// In your component:
return (
  <div>
    {allPosts.map((post) => (
      <div key={post.id}>{post.title}</div>
    ))}

    {hasNextPage && (
      <button onClick={() => fetchNextPage()} disabled={isFetchingNextPage}>
        {isFetchingNextPage ? "Loading more..." : "Load More"}
      </button>
    )}
  </div>
);

API Reference

useQuery

const { data, isLoading, error, refetch } = useQuery({
  queryKey: ["users", userId],
  queryFn: fetchUser,
  enabled: boolean,
  staleTime: number,
  retry: boolean | number,
});
  • queryKey: Unique key for the query (string or array)
  • queryFn: Function that returns a promise (fetcher)
  • enabled: (optional) Enable/disable the query
  • staleTime: (optional) Time in ms before data is considered stale
  • retry: (optional) Number of retry attempts or boolean

useMutation

const { mutate, isLoading, error, data } = useMutation({
  mutationFn: addTodo,
  onSuccess?: (data) => void,
  onError?: (error) => void,
  retry?: boolean | number
});
  • mutationFn: Function that performs the mutation (returns a promise)
  • onSuccess: (optional) Callback on successful mutation
  • onError: (optional) Callback on mutation error
  • retry: (optional) Number of retry attempts or boolean

useInfiniteQuery

const {
  data,
  isLoading,
  error,
  fetchNextPage,
  hasNextPage,
  isFetchingNextPage,
} = useInfiniteQuery({
  queryKey: ["posts"],
  queryFn: fetchPostPage,
  getNextPageParam: (lastPage, allPages, lastPageParam) => lastPage.nextCursor,
  initialPageParam: 0,
});
  • queryKey: Unique key for the query
  • queryFn: Function that fetches a page of data
  • getNextPageParam: (optional) Function to determine the next page parameter
  • initialPageParam: (optional) Initial page parameter value
  • Returns paginated data and utilities for infinite scrolling

QueryClient

  • .getState(queryKey): Get the state of a specific query
  • .invalidateQueries(queryKey): Invalidate and refetch queries

License

MIT

Important note

  • This is lib is only working with react+vite project, will soon fix the webpack issue. Happy web development.
  • If facing any issue while using, feel free to raise issue: https://github.com/anandsurya1590/zustand-query/issues