ワンクリックで
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.