A lightweight React data-fetching library with caching, mutations, REST & GraphQL support, and request deduplication.
npm install reactive-query-z !Downloads
reactive-query-z is a lightweight, reactive data-fetching library for React, built with hooks and TypeScript in mind.
> Minimal API surface, predictable behavior, and production-ready features.
---
* β‘ Lightweight & hook-based
* π REST + GraphQL support
* βοΈ Full CRUD mutations
* πΎ Cache with global invalidation
* π Optimistic UI updates
* β»οΈ Stale-while-revalidate
* π‘ Real-time subscriptions (WebSocket / SSE)
* π§© Middleware system (auth, logging, retry, timeoutβ¦)
* π§ TypeScript-first API
Note: For full-featured query management, see React Query
---
``bash`
npm install reactive-query-zor
yarn add reactive-query-z
---
`ts
import { useQuery, queryRegistry } from "reactive-query-z";
type User = { id: string; title: string };
function UserList() {
const {
data: users,
loading,
refetch,
error,
} = useQuery
cacheKey: "users-list",
// staleTime: 5000,
cacheTime: 10000,
// autoFetch: true,
headers: { "Content-Type": "application/json" },
});
return (
Loading...
}Error: {error.message}
}
---
$3
`ts
import { useGraphQLQuery } from "reactive-query-z";type Country = { code: string; name: string; emoji: string };
export function CountriesList() {
const { data, loading, error, refetch } = useGraphQLQuery<{ countries: Country[] }>(
"https://countries.trevorblades.com/",
{
query:
,
cacheKey: "countries",
}
); if (loading) return
Loading...
;
if (error) return {error.message}
; return (
{data?.countries?.map(c => (
- {c.name} {c.emoji}
))}
);
}
`---
$3
`ts
import { useMutation, queryRegistry } from "reactive-query-z";type Post = {
userId: number;
id: number;
title: string;
body: string;
};
export function AddPost() {
const { mutate, loading } = useMutation(
"https://jsonplaceholder.typicode.com/posts",
{
cacheKey: "posts",
optimisticUpdate: (prev, newPost) => newPost,
onSuccess: () => queryRegistry.invalidate("posts"),
}
);
const handleAdd = () => {
mutate({
title: "New Post",
body: "This is a new post",
userId: 1,
});
};
return (
);
}
`---
$3
`ts
import { useGraphQLMutation, queryRegistry } from "reactive-query-z";export function AddPostGraphQL() {
const { mutate, loading } = useGraphQLMutation(
"https://graphqlzero.almansi.me/api",
{
mutation:
,
variables: { title: "Hello", body: "World", userId: 122 },
onSuccess: () => queryRegistry.invalidate("postsGraphQL"),
}
); return (
);
}
`---
$3
`ts
import { queryRegistry, setGlobalErrorHandler } from "reactive-query-z";queryRegistry.invalidate("users"); // specific
queryRegistry.invalidate(); // all queries
setGlobalErrorHandler((error, info) => {
console.error("Global fetch error:", error, info);
});
`---
$3
`ts
import { useHybridQuery } from "reactive-query-z";const { data } = useHybridQuery("/graphql", {
subscriptionUrl: "ws://localhost:4000",
cacheKey: "messages",
});
`---
$3
#### πΉ queryClient.fetchQuery
`ts
import { queryClient } from "reactive-query-z";await queryClient.fetchQuery(
"https://jsonplaceholder.typicode.com/users",
{ cacheKey: "users" }
);
`#### πΉ queryClient.ensureQueryData (recommended)
`ts
import { queryClient, useQuery } from "reactive-query-z";type User = { id: number; name: string };
async function preloadUsers() {
await queryClient.ensureQueryData(
"https://jsonplaceholder.typicode.com/users",
{ cacheKey: "users" }
);
}
function Users() {
const { data, loading } = useQuery(
"https://jsonplaceholder.typicode.com/users",
{ cacheKey: "users" }
);
if (loading) return
Loading...
; return (
{data?.map((u) => (
- {u.name}
))}
);
}
`---
π§ API Reference
`ts
useQuery
useMutation
useGraphQLQuery
useGraphQLMutation
useHybridQueryqueryClient
queryRegistry
prefetchQuery
prefetchData
fetchWithRetry
commonFetch
setGlobalErrorHandler
``---
| Feature | reactive-query-z | React Query | SWR | Apollo Client |
| ------------------------- | ---------------- | ----------- | ---- | ------------- |
| REST support | β
| β
| β
| β οΈ Partial |
| GraphQL support | β
| β οΈ Plugin | β | β
|
| Real-time subscription | β
| β οΈ Plugin | β | β
|
| Global cache invalidation | β
| β
| β οΈ | β
|
| Optimistic updates | β
| β
| β οΈ | β
|
| Stale-while-revalidate | β
| β
| β
| β
|
| Full CRUD mutations | β
| β
| β | β
|
| TypeScript-first | β
| β
| β
| β
|
| Lightweight | β
| β οΈ | β
| β οΈ |
| Subscription built-in | β
| β | β | β
|
---
---
---
MIT