areas/software/frontend/skills/state-management/SKILL.md
# Skill: State Management ## When to load When deciding where to put state, choosing between local/global state, integrating server state, or debugging stale data. ## State Classification Matrix | State Type | Example | Solution | |:---|:---|:---| | **Local UI State** | Modal open/close, input focus | `useState` / `useReducer` | | **Shared UI State** | Theme, sidebar collapse | React Context + `useReducer` | | **Server/Remote State** | API data, pagination | React Query / SWR | | **URL State
npx skillsauth add sawrus/agent-guides areas/software/frontend/skills/state-managementInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When deciding where to put state, choosing between local/global state, integrating server state, or debugging stale data.
| State Type | Example | Solution |
|:---|:---|:---|
| Local UI State | Modal open/close, input focus | useState / useReducer |
| Shared UI State | Theme, sidebar collapse | React Context + useReducer |
| Server/Remote State | API data, pagination | React Query / SWR |
| URL State | Filters, search params | useSearchParams |
| Global App State | Auth session, shopping cart | Zustand / Redux Toolkit |
| Form State | Input values, validation errors | React Hook Form |
State should live as close to where it's used as possible. Only lift state up when two components genuinely need to share it.
❌ Storing modal visibility in a global store
✅ Storing modal visibility in the component that renders the modal
const { data } = useQuery({
queryKey: ['users', { page, filters }],
queryFn: () => fetchUsers({ page, filters }),
staleTime: 5 * 60 * 1000,
});
const mutation = useMutation({
mutationFn: createUser,
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['users'] }),
});
export const useAuthStore = create<AuthState>((set) => ({
user: null,
token: null,
login: async (credentials) => {
const { user, token } = await authApi.login(credentials);
set({ user, token });
},
logout: () => set({ user: null, token: null }),
}));
testing
QA Expert for writing E2E tests, test scenarios, test plans, and ensuring test coverage quality.
development
Expert UI/UX design intelligence for creating distinctive, high-craft, and mobile-first interfaces. Focuses on premium aesthetics, touch-first ergonomics, and Flutter performance.
development
Code Review Expert for static analysis, security auditing, architecture review, and ensuring code quality standards.
development
Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep watching open PRs so fresh review feedback is surfaced promptly. Use when the user asks Codex to monitor a PR, watch CI, handle review comments, or keep an eye on failures and feedback on an open PR.