首页/ AI 技能 / @skilllib/skill-2014279396910116867
Skill站外收录 @skilllib/skill-2014279396910116867

api-patterns

提供标准化的 API 调用与响应处理能力,涵盖数据查询、变更操作、缓存同步、错误提示及 Protobuf 协议集成,确保前后端通信一致、可靠且易于维护。

0.0 (0) 144 次安装 原作者 编程导航
收录于 2026-01-22
效率工具 AI 技能

Skills.MD

# API Patterns Make API calls with Connect Query and handle responses properly. ## Activation Conditions - Making API calls - Using Connect Query hooks - Cache invalidation - Mutations and optimistic updates - Toast notifications for errors ## Quick Reference | Action | Rule | |--------|------| | Fetch data | `use-connect-query.md` | | After mutation | `api-invalidate-cache.md` | | Handle errors | `api-toast-errors.md` (use `formatToastErrorMessage` in onError) | | Protobuf files | `protobuf-no-edit.md` | ## Key Locations | Location | Purpose | |----------|---------| | `/src/react-query/` | Connect Query hooks | | `/src/protogen/` | Generated protos (DO NOT EDIT) | Regenerate protos: `task proto:generate` (from repo root) ## Basic Patterns ### Query ```typescript import { useQuery } from '@connectrpc/connect-query'; import { getUser } from 'protogen/user-UserService_connectquery'; const { data, isLoading, error } = useQuery( getUser, { id: userId }, { enabled: !!userId } ); ``` ### Mutation ```typescript import { useMutation } from '@connectrpc/connect-query'; import { createUser } from 'protogen/user-UserService_connectquery'; const mutation = useMutation(createUser, { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['getUser'] }); }, }); mutation.mutate({ name, config }); ``` ## Rules See `rules/` directory for detailed guidance.

评论 0

还没有评论,来抢沙发。