{"id":18777763,"url":"https://github.com/arn4v/tsrq","last_synced_at":"2026-05-01T00:31:48.937Z","repository":{"id":96542080,"uuid":"412111875","full_name":"arn4v/tsrq","owner":"arn4v","description":"Generate type-safe React Query hooks without boilerplate","archived":false,"fork":false,"pushed_at":"2021-10-03T21:47:17.000Z","size":222,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-21T05:11:39.584Z","etag":null,"topics":["react","react-hooks","react-query","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/tsrq","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arn4v.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-09-30T15:07:10.000Z","updated_at":"2023-03-04T08:21:11.000Z","dependencies_parsed_at":"2023-04-04T06:17:53.539Z","dependency_job_id":null,"html_url":"https://github.com/arn4v/tsrq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arn4v/tsrq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arn4v%2Ftsrq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arn4v%2Ftsrq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arn4v%2Ftsrq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arn4v%2Ftsrq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arn4v","download_url":"https://codeload.github.com/arn4v/tsrq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arn4v%2Ftsrq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32481553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","react-hooks","react-query","typescript"],"created_at":"2024-11-07T20:13:44.010Z","updated_at":"2026-05-01T00:31:48.922Z","avatar_url":"https://github.com/arn4v.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003e\u003cb\u003e\u003ccenter\u003etsrq\u003c/center\u003e\u003c/b\u003e\u003c/h1\u003e\n\n- [Introduction](#introduction)\n- [Install](#install)\n- [Quick Start Example:](#quick-start-example)\n- [API Reference](#api-reference)\n- [Credits](#credits)\n\n## Introduction\n\nWhen 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.\n\nWith TSRQ, you only define you write code for your queries and mutations once and reuse them wherever you want.\n\n## Install\n\nnpm:\n\n```bash\nnpm i -S tsrq react-query\n```\n\nyarn:\n\n```bash\nyarn add tsrq react-query\n```\n\n## Quick Start Example:\n\n```tsx\nimport {\n\tcreateQueryBuilder,\n\tcreateUseQuery,\n\tcreateUseMutation,\n} from \"typed-query\";\n\ninterface ITodo {\n\tid: string;\n\ttitle: string;\n}\n\nconst builder = createQueryBuilder()\n\t.query(\"todos\", async () =\u003e {\n\t\treturn await fetch(\"/todos\").then(res =\u003e res.json() as Array\u003cITodo\u003e);\n\t})\n\t.query(\"byId\", async (id: string) =\u003e {\n\t\treturn await fetch(`/todos/${id}`).then(res =\u003e res.json() as ITodo);\n\t})\n\t.mutation(\"updateTodo\", async ({ id, title }: ITodo) =\u003e {\n\t\treturn await fetch(`/todos/${id}`, {\n\t\t\tmethod: \"PATCH\",\n\t\t\tbody: JSON.stringify({ title }),\n\t\t}).then(res =\u003e res.json() as ITodo);\n\t});\n\nconst useQuery = createUseQuery(builder);\nconst useMutation = createUseMutation(builder);\n\nexport default function TodosList() {\n\t// If query requires no parameters then you must\n\t// provide an empty array\n\tconst { data } = useQuery(\"todos\", []);\n\n\treturn (\n\t\t\u003cul\u003e\n\t\t\t{data?.map(item =\u003e (\n\t\t\t\t\u003cli key={item.id}\u003e{item.title}\u003c/li\u003e\n\t\t\t))}\n\t\t\u003c/ul\u003e\n\t);\n}\n\nexport default function TodoPage({ id }: { id: string }) {\n\t// Provide query parameters as array in second arg\n\tconst { data } = useQuery(\"byId\", [id]);\n\tconst { mutate } = useMutation(\"updateTodo\");\n\n\treturn \u003cdiv\u003e{data?.title}\u003c/div\u003e;\n}\n```\n\n## API Reference\n\n- createQueryBuilder\n\nCreate instance:\n\n```ts\nimport { createQueryBuilder } from \"tsrq\";\n\nconst builder = createQueryBuilder();\n```\n\nAdd Query to Instance:\n\n```ts\nimport { createQueryBuilder } from \"tsrq\";\n\nconst builder = createQueryBuilder().query(\"todos\", () =\u003e {\n\treturn fetch(\"/todos\").then(res =\u003e res.json());\n});\n```\n\nAdd Mutation to Instance:\n\n```ts\nimport { createQueryBuilder } from \"tsrq\";\n\nconst builder = createQueryBuilder().mutation(\"add\", (title: string) =\u003e {\n\treturn fetch(\"/todos\", {\n\t\tmethod: \"POST\",\n\t\tbody: JSON.stringify({\n\t\t\ttitle,\n\t\t}),\n\t});\n});\n```\n\n- createUseQuery\n\n```ts\nimport { createQueryBuilder, createUseQuery } from \"tsrq\";\n\n// Builder Code\nconst builder = createQueryBuilder();\n// ...End Builder Code\n\nexport const useQuery = createUseQuery(builder);\n```\n\nUsage:\n\nWhen query requires params:\n\n```tsx\nimport * as React from \"react\";\nimport { useQuery } from \"./tsrq.config\";\n\nconst TodoPage = ({ id }: { id: string }) =\u003e {\n\tconst { data, isLoading } = useQuery(\"byId\", [id]);\n\n\tif (isLoading) return null;\n\n\treturn \u003cdiv\u003e{/** JSX */}\u003c/div\u003e;\n};\n```\n\nWhen query doesn't require params:\n\n```tsx\nimport * as React from \"react\";\nimport { useQuery } from \"./tsrq.config\";\n\nexport default function TodosList() {\n\t// If query requires no parameters then you must\n\t// provide an empty array\n\tconst { data } = useQuery(\"todos\", []);\n\n\treturn (\n\t\t\u003cul\u003e\n\t\t\t{data?.map(item =\u003e (\n\t\t\t\t\u003cli key={item.id}\u003e{item.title}\u003c/li\u003e\n\t\t\t))}\n\t\t\u003c/ul\u003e\n\t);\n}\n```\n\n- createUseMutation\n\n```ts\nimport { createQueryBuilder, createUseMutation } from \"tsrq\";\n\n// Builder Code\nconst builder = createQueryBuilder();\n// ...End Builder Code\n\nexport const useMutation = createUseMutation(builder);\n```\n\nUsage:\n\n```tsx\nimport * as React from \"react\";\nimport { useMutation } from \"./tsrq.config\";\n\nconst CreateTodoPage = () =\u003e {\n\tconst [title, setTitle] = React.useState(\"\");\n\tconst { mutate } = useMutation(\"add\");\n\n\tconst addTodo = () =\u003e {\n\t\tmutate(title);\n\t};\n\treturn \u003cdiv\u003e{/** JSX */}\u003c/div\u003e;\n};\n```\n\n## Credits\n\n- Alex Johansson (@katt) for tRPC. This library is heavily inspired by `trpc`. TSRQ QueryBuilder implementation is similar to TRPC's Router implementation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farn4v%2Ftsrq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farn4v%2Ftsrq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farn4v%2Ftsrq/lists"}