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

tsrq

v0.0.8

Published

When using React Query, for the same query, you can either copy paste the code into different components or abstract it into a custom hook. The first one is just bad practice and the second method become unmanageable very quickly as your app (and # of end

Downloads

7

Readme

Introduction

When using React Query, for the same query, you can either copy paste the code into different components or abstract it into a custom hook. The first one is just bad practice and the second method become unmanageable very quickly as your app (and # of endpoints) grows.

With TSRQ, you only define you write code for your queries and mutations once and reuse them wherever you want.

Install

npm:

npm i -S tsrq react-query

yarn:

yarn add tsrq react-query

Quick Start Example:

import {
	createQueryBuilder,
	createUseQuery,
	createUseMutation,
} from "typed-query";

interface ITodo {
	id: string;
	title: string;
}

const builder = createQueryBuilder()
	.query("todos", async () => {
		return await fetch("/todos").then(res => res.json() as Array<ITodo>);
	})
	.query("byId", async (id: string) => {
		return await fetch(`/todos/${id}`).then(res => res.json() as ITodo);
	})
	.mutation("updateTodo", async ({ id, title }: ITodo) => {
		return await fetch(`/todos/${id}`, {
			method: "PATCH",
			body: JSON.stringify({ title }),
		}).then(res => res.json() as ITodo);
	});

const useQuery = createUseQuery(builder);
const useMutation = createUseMutation(builder);

export default function TodosList() {
	// If query requires no parameters then you must
	// provide an empty array
	const { data } = useQuery("todos", []);

	return (
		<ul>
			{data?.map(item => (
				<li key={item.id}>{item.title}</li>
			))}
		</ul>
	);
}

export default function TodoPage({ id }: { id: string }) {
	// Provide query parameters as array in second arg
	const { data } = useQuery("byId", [id]);
	const { mutate } = useMutation("updateTodo");

	return <div>{data?.title}</div>;
}

API Reference

  • createQueryBuilder

Create instance:

import { createQueryBuilder } from "tsrq";

const builder = createQueryBuilder();

Add Query to Instance:

import { createQueryBuilder } from "tsrq";

const builder = createQueryBuilder().query("todos", () => {
	return fetch("/todos").then(res => res.json());
});

Add Mutation to Instance:

import { createQueryBuilder } from "tsrq";

const builder = createQueryBuilder().mutation("add", (title: string) => {
	return fetch("/todos", {
		method: "POST",
		body: JSON.stringify({
			title,
		}),
	});
});
  • createUseQuery
import { createQueryBuilder, createUseQuery } from "tsrq";

// Builder Code
const builder = createQueryBuilder();
// ...End Builder Code

export const useQuery = createUseQuery(builder);

Usage:

When query requires params:

import * as React from "react";
import { useQuery } from "./tsrq.config";

const TodoPage = ({ id }: { id: string }) => {
	const { data, isLoading } = useQuery("byId", [id]);

	if (isLoading) return null;

	return <div>{/** JSX */}</div>;
};

When query doesn't require params:

import * as React from "react";
import { useQuery } from "./tsrq.config";

export default function TodosList() {
	// If query requires no parameters then you must
	// provide an empty array
	const { data } = useQuery("todos", []);

	return (
		<ul>
			{data?.map(item => (
				<li key={item.id}>{item.title}</li>
			))}
		</ul>
	);
}
  • createUseMutation
import { createQueryBuilder, createUseMutation } from "tsrq";

// Builder Code
const builder = createQueryBuilder();
// ...End Builder Code

export const useMutation = createUseMutation(builder);

Usage:

import * as React from "react";
import { useMutation } from "./tsrq.config";

const CreateTodoPage = () => {
	const [title, setTitle] = React.useState("");
	const { mutate } = useMutation("add");

	const addTodo = () => {
		mutate(title);
	};
	return <div>{/** JSX */}</div>;
};

Credits

  • Alex Johansson (@katt) for tRPC. This library is heavily inspired by trpc. TSRQ QueryBuilder implementation is similar to TRPC's Router implementation.