data-fetching
Installation
SKILL.md
Data Fetching Patterns
1. Basic Query with TanStack Query
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
interface User {
id: string;
name: string;
email: string;
}
// API functions
async function fetchUser(userId: string): Promise<User> {
const res = await fetch(`/api/users/${userId}`);
if (!res.ok) throw new Error("Failed to fetch user");
return res.json();
}