rtk-query-api

Create RTK Query API slices with typed endpoints and exported hooks.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/Ledger-Wallet-LLC/ledgerwallet --skill rtk-query-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rtk-query-api
Source: https://github.com/Ledger-Wallet-LLC/ledgerwallet/tree/main/.cursor/skills/rtk-query-api
Command: npx skills add https://github.com/Ledger-Wallet-LLC/ledgerwallet --skill rtk-query-api

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

RTK Query API best practices for designing robust data-fetching slices with RTK Query. This skill guides developers to structure one API slice per base URL, define endpoints with build.query/build.mutation, and export generated hooks, ensuring consistent data management across apps.

Core Features & Use Cases

  • One API slice per base URL / data source
  • Define API slices in state-manager/api.ts
  • Export generated hooks alongside the API
  • Use build.query for GET requests
  • Use build.mutation for POST/PUT/DELETE
  • Type both response and argument: build.query<ResponseType, ArgType>
  • Use transformResponse to reshape API data
  • Use transformErrorResponse for custom error handling
  • Register APIs in reducers/rtkQueryApi.ts

Quick Start

Create an API slice with createApi for your base URL, define GET and mutation endpoints, and export the generated hooks.

Frequently Asked Questions about rtk-query-api

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

FAQPage Schema
How do I structure RTK Query API slices for multiple base URLs?

Organize RTK Query API slices by creating one distinct API slice per base URL or data source. Define these slices in state-manager/api.ts and register them in reducers/rtkQueryApi.ts to ensure consistent state management.

What is the best way to type build.query and build.mutation endpoints in Redux Toolkit?

The best way to type build.query and build.mutation endpoints is by explicitly defining both the response and argument types, such as build.query<ResponseType, ArgType>. This ensures strong type safety across your API slices.

How do I reshape API data or handle errors with RTK Query?

To reshape API data or handle errors with RTK Query, use the transformResponse function to modify successful response payloads and transformErrorResponse for custom error handling before the data reaches your reducers.

When should I use build.query versus build.mutation for data fetching?

Use build.query for GET requests to fetch data and build.mutation for POST, PUT, or DELETE requests that modify data. This distinction ensures proper cache invalidation and hook generation for consuming components.

How do I invalidate cached data in RTK Query after a mutation?

Invalidate cached data in RTK Query by defining tagTypes in your API slice and attaching providesTags to queries and invalidatesTags to mutations. This ensures cached data is automatically refreshed after modifications.