new-query

Generate TanStack Query hooks that call backend actions directly.

13|5|Updated May 18, 2024
One-click install
npx skills add https://github.com/techdiary-dev/techdiary.dev --skill new-query
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: new-query
Source: https://github.com/techdiary-dev/techdiary.dev/tree/main/.claude/skills/new-query
Command: npx skills add https://github.com/techdiary-dev/techdiary.dev --skill new-query

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Reduces boilerplate by scaffolding TanStack Query hooks that call backend actions directly, avoiding the need for extra API routes and repetitive setup.

Core Features & Use Cases

  • Use useQuery and useMutation templates to fetch and mutate data with server actions
  • Import server actions directly from "@/backend/services/<domain>.action" without API routes
  • Enforce a standardized QueryKey format like ["<resource>", param1, param2]
  • Support enabled flags and optimistic updates with proper error handling
  • Invalidate or refresh related queries via useQueryClient on mutation success

Quick Start

Create a feature hook by importing the backend action and wiring it into useQuery or useMutation using the provided templates.

Frequently Asked Questions about new-query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call server actions directly with TanStack Query hooks without creating API routes?

To call server actions directly, you can generate TanStack Query hooks that import actions from your backend domain files, avoiding extra API routes by wiring them straight into useQuery or useMutation templates.

What is the best way to structure TanStack Query keys for React hooks fetching backend actions?

The best way to structure TanStack Query keys is using a standardized array format like ["<resource>", param1, param2], ensuring consistent cache invalidation when you trigger useQueryClient updates on mutation success.

How do you handle optimistic updates and error handling in React hooks using TanStack Query?

You handle optimistic updates and error handling by applying specific useMutation templates that support enabled flags and proper error handling, automatically rolling back changes if the server action fails.

Does TanStack Query work with React server actions for data fetching and mutations?

Yes, TanStack Query works seamlessly with React server actions by importing them directly into useQuery and useMutation hooks, enabling both data fetching and write operations with toast notifications on success.

How do I invalidate related TanStack Query caches after a successful useMutation?

You invalidate related TanStack Query caches by using useQueryClient on mutation success, triggering a refresh of dependent useQuery hooks by targeting their standardized query key arrays.

Can I disable a TanStack Query hook conditionally when fetching backend actions?

Yes, you can conditionally disable a TanStack Query hook by utilizing supported enabled flags within the useQuery template, preventing automatic data fetching until your specified conditions are met.