API çağrılarını, cache'i, loading state'i manuel mi yönetiyorsun? Bırak TanStack yapsın.
Nedir?
Server state yönetimi için endüstri standardı. Fetching, caching, syncing otomatik.
Kurulum
npm install @tanstack/react-query
Kullanım
import { useQuery, QueryClient, QueryClientProvider } from '@tanstack/react-query';const queryClient = new QueryClient();function App() { return ( <QueryClientProvider client={queryClient}> <UserProfile /> </QueryClientProvider> );}function UserProfile() { const { data, isLoading, error } = useQuery({ queryKey: ['user'], queryFn: () => fetch('/api/user').then(r => r.json()), }); if (isLoading) return <Text>Yükleniyor...</Text>; if (error) return <Text>Hata!</Text>; return <Text>{data.name}</Text>;}
Neden Kullanmalısın?
- Otomatik cache
- Background refetch
- Optimistic updates
- Infinite scroll desteği
Link: tanstack.com/query