一键导入
data-state-management
Specifications for Zustand stores, React Query hooks, and the Service-Hook-Type pattern with optimistic updates.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Specifications for Zustand stores, React Query hooks, and the Service-Hook-Type pattern with optimistic updates.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
ZGO API development standards including pagination, error handling, and RESTful design
Test patterns, mocking strategies, and organization best practices
Standardized error format, error code clusters, and API client usage for consistent error handling.
Strict rules for environment variable management using Zod validation and src/config/env.ts.
Guidelines for managing internationalization (i18n) in the project using next-intl and unified translation patterns.
High-level overview of project structure, mock API architecture, and authentication flow.
| name | data-state-management |
| description | Specifications for Zustand stores, React Query hooks, and the Service-Hook-Type pattern with optimistic updates. |
This skill outlines the state management architecture of the project. It focuses on the separation of concerns between stateless services, React Query hooks for server state, and Zustand for global UI state.
src/store/auth-store.ts (Zustand + persist). Stores user data and system features.src/store/ui-store.ts (Zustand). Temporary/global UI states.All data handling must follow this layered architecture:
src/types/*.ts)Strictly type all domain models, DTOs, and query schemas.
src/services/*.ts)Pure functional objects that wrap HTTP requests. They do not hold state or use hooks.
import request from '@/http/request';
export const userService = {
get: () => request.get('/user'),
update: (id: string, data: UserUpdate) => request.patch(`/user/${id}`, data)
};
src/hooks/*.ts)Manage React Query state and side effects. Implement full CRUD with optimistic updates.
export function useUpdateExample() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, data }) => exampleService.update(id, data),
onMutate: async ({ id, data }) => {
await queryClient.cancelQueries({ queryKey: exampleKeys.detail(id) });
const prev = queryClient.getQueryData(exampleKeys.detail(id));
if (prev) queryClient.setQueryData(exampleKeys.detail(id), { ...prev, ...data });
return { prev };
},
onError: (err, { id }, context) => {
queryClient.setQueryData(exampleKeys.detail(id), context.prev);
toast.error(err.message);
},
onSettled: (data, err, { id }) => {
queryClient.invalidateQueries({ queryKey: exampleKeys.detail(id) });
}
});
}
[!TIP] Stateless Services: Always use the appropriate request instance (e.g.,
requestvsfileRequest) fromsrc/http/request.ts.