Setup state management for React applications using Zustand, TanStack Query, and React Hook Form. Use when users need to manage client state, server state, or form state. Covers store patterns, caching strategies, and form validation.
/plugin marketplace add leobrival/topographic-studio-plugins/plugin install code-workflows@topographic-studio-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/forms/user-form.tsxassets/tanstack-query/query-client.tsassets/tanstack-query/use-users.tsassets/zustand/app-store.tsassets/zustand/create-store.tsassets/zustand/user-store.tsreferences/form-patterns.mdreferences/tanstack-query.mdreferences/zustand-patterns.mdModern state management patterns for React applications.
User request → What type of state?
│
├─ Client State (UI, local)
│ ├─ Zustand → Simple, minimal boilerplate
│ ├─ Jotai → Atomic, fine-grained
│ ├─ Valtio → Proxy-based, mutable API
│ └─ Context → Built-in, simple cases
│
├─ Server State (API data)
│ ├─ TanStack Query → Caching, background sync
│ ├─ SWR → Lightweight, stale-while-revalidate
│ └─ RTK Query → Redux ecosystem
│
├─ Form State
│ ├─ React Hook Form → Performance, validation
│ ├─ Formik → Mature, feature-rich
│ └─ Conform → Progressive enhancement
│
└─ URL State
├─ nuqs → Type-safe URL params
└─ useSearchParams → Built-in Next.js
pnpm add zustand
// stores/useUserStore.ts
import { create } from "zustand";
import { persist, devtools } from "zustand/middleware";
interface User {
id: string;
email: string;
name: string;
}
interface UserState {
user: User | null;
isAuthenticated: boolean;
setUser: (user: User) => void;
logout: () => void;
}
export const useUserStore = create<UserState>()(
devtools(
persist(
(set) => ({
user: null,
isAuthenticated: false,
setUser: (user) => set({ user, isAuthenticated: true }),
logout: () => set({ user: null, isAuthenticated: false }),
}),
{ name: "user-storage" }
)
)
);
pnpm add @tanstack/react-query @tanstack/react-query-devtools
// lib/query-client.ts
import { QueryClient } from "@tanstack/react-query";
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 60 * 1000, // 1 minute
gcTime: 5 * 60 * 1000, // 5 minutes
retry: 1,
refetchOnWindowFocus: false,
},
},
});
// hooks/useUsers.ts
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { api } from "@/lib/api";
export function useUsers() {
return useQuery({
queryKey: ["users"],
queryFn: () => api.get("/users"),
});
}
export function useUser(id: string) {
return useQuery({
queryKey: ["users", id],
queryFn: () => api.get(`/users/${id}`),
enabled: !!id,
});
}
export function useCreateUser() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: CreateUserInput) => api.post("/users", data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["users"] });
},
});
}
pnpm add react-hook-form @hookform/resolvers zod
// components/UserForm.tsx
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
const userSchema = z.object({
email: z.string().email("Invalid email"),
name: z.string().min(2, "Name too short"),
password: z.string().min(8, "Password must be 8+ characters"),
});
type UserFormData = z.infer<typeof userSchema>;
export function UserForm({ onSubmit }: { onSubmit: (data: UserFormData) => void }) {
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm<UserFormData>({
resolver: zodResolver(userSchema),
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("email")} placeholder="Email" />
{errors.email && <span>{errors.email.message}</span>}
<input {...register("name")} placeholder="Name" />
{errors.name && <span>{errors.name.message}</span>}
<input {...register("password")} type="password" placeholder="Password" />
{errors.password && <span>{errors.password.message}</span>}
<button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Submitting..." : "Submit"}
</button>
</form>
);
}
| State Type | Solution | Persistence | Sync |
|---|---|---|---|
| UI State | Zustand | Optional | No |
| Server State | TanStack Query | Cache | Background |
| Form State | React Hook Form | No | No |
| URL State | nuqs | URL | Browser |
| Auth State | Zustand + persist | LocalStorage | No |
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.