data-fetching
Data fetching with TanStack Query, loading states, and error handling
Security Assessment
About data-fetching
The `data-fetching` skill provides a structured approach to handling data retrieval, updates, and pagination in React applications using TanStack Query. It addresses common challenges in modern web development, such as managing loading states, error handling, and keeping UI data synchronized with server data. By leveraging this skill, developers can streamline asynchronous data operations and maintain responsive, interactive interfaces without manually managing complex state logic or repetitive fetch patterns.
This skill includes several key capabilities: basic queries to fetch individual data records, mutations with optimistic updates for smoother user experiences, infinite scrolling and pagination for handling large datasets, and dependent queries that execute based on the availability of prior data. Each pattern demonstrates practical integration with React components, including error handling, loading skeletons, and automatic cache invalidation. The examples provided cover both simple data fetching scenarios and more advanced operations like rollback on mutation errors, ensuring robust and predictable application behavior.
Typical use cases for this skill include building user dashboards, content management systems, and interactive applications that rely on up-to-date server data. It is particularly useful for front-end developers working with React who need to implement efficient data handling with minimal boilerplate. By following these patterns, teams can reduce bugs, improve user experience, and maintain a clear separation between data logic and UI components, making the development process faster and more maintainable.
FAQ
How do I fetch a single user with this skill?
You can use the basic query pattern with `useQuery`, providing a unique query key and a query function that fetches the user data from your API.
Can I perform updates with optimistic UI feedback?
Yes, the skill includes a mutation pattern using `useMutation` with an `onMutate` callback for optimistic updates and rollback on error, ensuring smooth user experience during data changes.
Is this compatible with infinite scrolling or paginated data?
Yes, the skill demonstrates the use of `useInfiniteQuery` to fetch paginated data, manage loading states, and fetch additional pages as needed.
Are queries dependent on other queries supported?
Yes, dependent queries can be implemented using the `enabled` option in `useQuery`, ensuring that subsequent queries only run when prerequisite data is available.
What are the requirements for using this skill?
This skill requires a React environment and TanStack Query (React Query) installed. The API endpoints should return JSON and handle standard HTTP responses for proper error handling.
Install data-fetching
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
emanueleielo/deepagents-open-lovable