skills/state-management/SKILL.md
Manage frontend state in React 19 applications. Covers local state, Context API, server state with TanStack Query, URL state, and state composition patterns. Use when: choosing a state management approach, implementing data fetching with caching, managing global UI state, or optimizing re-renders.
npx skillsauth add congiuluc/my-awesome-copilot 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.
| Category | Tool | Examples |
|----------|------|---------|
| Local UI | useState, useReducer | Form inputs, open/close, selection |
| Server | TanStack Query | API data, pagination, caching |
| Global UI | Context + useReducer | Theme, auth status, sidebar |
| URL | useSearchParams, router | Filters, sort, page number |
| Form | React Hook Form or controlled | Validation, submission, field state |
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
export function useProducts() {
return useQuery({
queryKey: ['products'],
queryFn: () => api.get<Product[]>('/api/products'),
staleTime: 5 * 60 * 1000, // 5 minutes
});
}
export function useCreateProduct() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: CreateProductRequest) => api.post('/api/products', data),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['products'] }),
});
}
queryKey arrays for cache identity.staleTime based on data freshness requirements.const ThemeContext = createContext<ThemeContextValue | null>(null);
export function ThemeProvider({ children }: { children: React.ReactNode }) {
const [theme, setTheme] = useState<'light' | 'dark'>('dark');
const value = useMemo(() => ({ theme, setTheme }), [theme]);
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
}
export function useTheme() {
const context = useContext(ThemeContext);
if (!context) throw new Error('useTheme must be used within ThemeProvider');
return context;
}
useMemo to prevent unnecessary re-renders.const [searchParams, setSearchParams] = useSearchParams();
const page = Number(searchParams.get('page')) || 1;
const sort = searchParams.get('sort') || 'name';
staleTime (causes unnecessary refetches)tools
Build VS Code extensions with TypeScript. Covers extension anatomy, activation events, commands, tree views, webview panels, language features, testing, and publishing. Use when: creating a new VS Code extension, adding commands/views/providers, building webview UIs, implementing language server features, testing extensions, or packaging for the marketplace.
development
Track implementations, features, bugs, and releases in a versioning document. Use when: adding a commit, completing a feature, fixing a bug, or preparing a release. Automatically updates CHANGELOG.md following Keep a Changelog format and Semantic Versioning.
development
Write frontend tests using Vitest and React Testing Library. Use when: testing React components, hooks, user interactions, form submissions, accessibility assertions, or mocking API services.
development
Write Angular frontend tests using Jasmine, Karma, and Angular TestBed. Use when: testing Angular components, services, pipes, directives, user interactions, form submissions, accessibility assertions, or mocking HTTP services.