tanstack-query
यह क्या करती है
यह स्किल एजेंट को TanStack Query वर्शन 5 से सर्वर डेटा लाने और कैश करने का मार्गदर्शन देती है। यह उन डेवलपर्स के लिए है जो React ऐप बनाते हैं जो किसी ऑनलाइन सेवा से डेटा लेते हैं।
कब इस्तेमाल करें
- ✓जब किसी React कॉम्पोनेंट को API से डेटा लाना हो।
- ✓जब आप चाहते हैं कि लोडिंग और कैशिंग एक एकसमान तरीके से संभाली जाएँ।
- ✓जब कोई कार्रवाई डेटा बदलती है और स्क्रीन को उससे मेल खाने के लिए ताज़ा होना चाहिए।
Skill का लिंक
https://github.com/Kiranism/next-shadcn-dashboard-starter/blob/main/.agents/skills/tanstack-query/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे React ऐप में ऑर्डर की सूची लाइए, और नया ऑर्डर जुड़ने के बाद उसे ताज़ा कीजिए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट query hooks और एक केंद्रीय API सर्विस फ़ाइल इस्तेमाल करता है, फिर बदलाव के बाद कैश किया डेटा ताज़ा या अपडेट करता है। वह वर्शन 5 के नामों और नियमों का पालन करता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
TanStack Query Patterns
Purpose
Modern data fetching with TanStack Query v5 (latest: 5.90.5, November 2025), emphasizing Suspense-based queries, cache-first strategies, and centralized API services.
Note: v5 (released October 2023) has breaking changes from v4:
isLoading→isPendingfor statuscacheTime→gcTime(garbage collection time)- React 18.0+ required
- Callbacks removed from useQuery (onError, onSuccess, onSettled)
keepPreviousDatareplaced withplaceholderDatafunction
When to Use This Skill
- Fetching data with TanStack Query
- Using useSuspenseQuery or useQuery
- Managing mutations
- Cache invalidation and updates
- API service patterns
Quick Start
Primary Pattern: useSuspenseQuery
For all new components, use useSuspenseQuery:
import { useSuspenseQuery } from '@tanstack/react-query';
import { postsApi } from '~/features/posts/api/postsApi';
function PostList() {
const { data: posts } = useSuspenseQuery({
queryKey: ['posts'],
queryFn: postsApi.getAll,
});
return (
<div>
{posts.map(post => (
<PostCard key={post.id} post={post} />
))}
</div>
);
}
// Wrap with Suspense
<Suspense fallback={<PostsSkeleton />}>
<PostList />
</Suspense>
Benefits:
- No
isLoadingchecks needed - Integrates with Suspense boundaries
- Cleaner component code
- Consistent loading UX
useSuspenseQuery Patterns
Basic Usage
const { data } = useSuspenseQuery({
queryKey: ['user', userId],
queryFn: () => userApi.get(userId),
});
// data is never undefined - guaranteed by Suspense
return <div>{data.name}</div>;
With Parameters
function UserPosts({ userId }: { userId: string }) {
const { data: posts } = useSuspenseQuery({
queryKey: ['users', userId, 'posts'],
queryFn: () => postsApi.getByUser(userId),
});
return <div>{posts.length} posts</div>;
}
Dependent Queries
function PostDetails({ postId }: { postId: string }) {
// First query
const { data: post } = useSuspenseQuery({
queryKey: ['posts', postId],
queryFn: () => postsApi.get(postId),
});
// Second query depends on first
const { data: author } = useSuspenseQuery({
queryKey: ['users', post.authorId],
queryFn: () => userApi.get(post.authorId),
});
return <div>{author.name} wrote {post.title}</div>;
}
useQuery (Legacy Pattern)
Use useQuery only when you need loading/error states in the component:
import { useQuery } from '@tanstack/react-query';
function Component() {
const { data, isPending, error } = useQuery({
queryKey: ['posts'],
queryFn: postsApi.getAll,
});
if (isPending) return <Spinner />;
if (error) return <Error error={error} />;
return <div>{data.map(...)}</div>;
}
When to use useQuery vs useSuspenseQuery:
- Use
useSuspenseQueryby default (preferred) - Use
useQueryonly when you need component-level loading states - Most cases should use
useSuspenseQuery+ Suspense boundaries
Mutations
Basic Mutation
import { useMutation, useQueryClient } from '@tanstack/react-query';
function CreatePostButton() {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: postsApi.create,
onSuccess: () => {
// Invalidate and refetch
queryClient.invalidateQueries({ queryKey: ['posts'] });
},
});
const handleCreate = () => {
mutation.mutate({
title: 'New Post',
content: 'Content here',
});
};
return (
<button onClick={handleCreate} disabled={mutation.isPending}>
{mutation.isPending ? 'Creating...' : 'Create Post'}
</button>
);
}
Optimistic Updates
const mutation = useMutation({
mutationFn: postsApi.update,
onMutate: async (updatedPost) => {
// Cancel outgoing refetches
await queryClient.cancelQueries({ queryKey: ['posts', updatedPost.id] });
// Snapshot previous value
const previousPost = queryClient.getQueryData(['posts', updatedPost.id]);
// Optimistically update
queryClient.setQueryData(['posts', updatedPost.id], updatedPost);
// Return context with snapshot
return { previousPost };
},
onError: (err, updatedPost, context) => {
// Rollback on error
queryClient.setQueryData(['posts', updatedPost.id], context.previousPost);
},
onSettled: (data, error, variables) => {
अक्सर पूछे जाने वाले सवाल
वर्शन 5 में क्या बदला?
कुछ नाम बदले, जैसे isLoading का isPending बनना, और queries से कुछ callbacks हटाए गए।
suspense लोडिंग क्या है?
डेटा लोड होते समय यह एक फ़ॉलबैक दिखाता है, इसलिए कॉम्पोनेंट को अपनी अलग लोडिंग जाँच नहीं चाहिए।
API कॉल कहाँ रहनी चाहिए?
स्किल एक केंद्रीय API सर्विस फ़ाइल की सिफ़ारिश करती है, जिसे query hooks कॉल करते हैं।
जानकारी
लेखक का मूल विवरण
TanStack Query v5 data fetching patterns including useSuspenseQuery, useQuery, mutations, cache management, and API service integration. Use when fetching data, managing server state, or working with TanStack Query hooks.
लोकप्रियता
- GitHub स्टार
- 7.2k
- रैंकिंग में स्थान
- #13312
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
kiranism-shadcn-dashboard
7.2kआपके एजेंट को Next.js एडमिन डैशबोर्ड में पेज, टेबल, फ़ॉर्म, नेविगेशन और थीम जोड़ने देती है, टेम्पलेट के अपने पैटर्न का पालन करते हुए।
next-best-practices
7.2kआपके एजेंट को रूट, सर्वर कॉम्पोनेंट, डेटा लोडिंग और एरर पेज के लिए मौजूदा सर्वोत्तम तरीकों से Next.js कोड लिखने और जाँचने में मदद करती है।
tanstack-form
7.2kआपके एजेंट को React और दूसरे फ़्रेमवर्क में टाइप-सुरक्षित फ़ॉर्म बनाने में मदद करती है, जिनमें फ़ील्ड जाँच, दोहराए जाने वाले फ़ील्ड और schema सत्यापन हों।
मिलती-जुलती skills
angular-developer
280kआपके एजेंट को Angular code बनाने और प्रोजेक्ट स्ट्रक्चर पर सलाह देने में मदद करता है। नए प्रोजेक्ट शुरू करने, code के हिस्से बनाने, या performance और accessibility सुधारने में उपयोगी है।
frontend-a11y
280kआपके एजेंट को web interfaces को सबके लिए accessible बनाने में मदद करता है। यह सुनिश्चित करता है कि websites और apps screen readers और keyboard navigation के साथ अच्छे से काम करें।
frontend-patterns
280kआपके एजेंट को React और Next.js में frontend development के modern patterns लागू करने में मदद करता है। यह performance optimize करता है, state manage करता है और best practices फॉलो करवाता है।