src/skills/web-state-redux-toolkit/SKILL.md
Redux Toolkit patterns for complex client state. Use when managing enterprise-scale state, needing DevTools, entity normalization, or RTK Query for data fetching.
npx skillsauth add agents-inc/skills web-state-redux-toolkitInstall 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.
Quick Guide: Use Redux Toolkit for complex client state requiring DevTools, middleware, or entity normalization. Use RTK Query for data fetching with caching. For simpler UI state, a lighter state management solution may be more appropriate. NEVER use legacy Redux patterns (createStore, combineReducers manually, switch statements in reducers).
Detailed Resources:
<critical_requirements>
(You MUST use configureStore for store setup - NEVER legacy createStore)
(You MUST use createSlice for all reducers - NEVER switch statements or manual action creators)
(You MUST define typed hooks (useAppSelector, useAppDispatch) once in a hooks file)
(You MUST use named exports ONLY - NO default exports in any Redux files)
(You MUST use named constants for ALL numbers - NO magic numbers in state code)
</critical_requirements>
Auto-detection: Redux Toolkit, createSlice, configureStore, RTK Query, createAsyncThunk, createEntityAdapter, useSelector, useDispatch
When to use:
Key patterns covered:
configureStorecreateSlice and Immer integrationcreateSlice, combineSlices, buildCreateSlice for async thunkscreateAsyncThunkWhen NOT to use:
Redux Toolkit (RTK) is the official, opinionated, batteries-included toolset for efficient Redux development. It eliminates the boilerplate of legacy Redux while maintaining predictable state management through strict unidirectional data flow.
Core principle: "One source of truth" - All application state lives in a single store, changes are made through pure reducer functions, and state is never mutated directly.
RTK uses Immer internally, allowing you to write "mutative" code that is actually immutable. This dramatically simplifies reducer logic while maintaining Redux's guarantees.
Key architecture decisions:
Use configureStore with proper TypeScript types inferred from the store itself.
For store setup, typed hooks, and middleware configuration examples, see examples/core.md.
Use createSlice to define reducers, actions, and initial state together. Immer allows "mutative" syntax for immutable updates.
For slice creation with typed state and PayloadAction, see examples/core.md.
Define typed versions of useDispatch and useSelector once, then use everywhere. This ensures type safety without repetitive type annotations.
useSelector saves typing (state: RootState) every timeuseDispatch default type does not know about thunksAppDispatch includes thunk middleware types for correct dispatch typingFor typed hooks setup with .withTypes() (React Redux v9.1.0+), see examples/typed-hooks.md.
RTK Query is a purpose-built data fetching and caching solution. Use it when you need caching, automatic refetching, and cache invalidation.
For createApi setup, endpoint definitions, and cache tags, see examples/rtk-query.md.
Use createEntityAdapter for collections of items (users, products, posts). It provides standardized CRUD operations and memoized selectors.
For entity adapter setup, CRUD operations, and selector usage, see examples/entity-adapters.md.
Use createAsyncThunk for async operations that need to dispatch multiple actions (pending, fulfilled, rejected).
For async thunk creation and handling lifecycle actions, see examples/async-thunks.md.
Create reusable selectors for derived state. Use createSelector from Reselect for memoized computed values.
For selector patterns and memoization, see examples/selectors.md.
Add custom middleware for logging, analytics, or side effects. Use the middleware callback to extend default middleware.
For middleware configuration and custom middleware, see examples/middleware.md.
</patterns><red_flags>
High Priority Issues:
createStore instead of configureStore -- misses DevTools, development checks, and middleware defaultscreateSlice which generates action creators automaticallycreateSlice generates these from reducer namescreateSlice/createReducerextraReducers -- removed in v2, use builder callbackAnyAction type deprecated -- use UnknownAction with isAction() guardMedium Priority Issues:
useDispatch/useSelector instead of typed hooks -- loses type safety for thunks and statehooks.tssetupListeners for RTK Query -- refetchOnFocus/refetchOnReconnect will not workrejectWithValue in thunks -- loses typed error handlingcreateSelector for derived data -- causes unnecessary recalculations on every renderGotchas & Edge Cases:
createSlice/createReducer -- not in action creators or thunksupdateOne/updateMany perform shallow merge -- deep nested updates need manual handling"User" !== "user"createAsyncThunk auto-dispatches pending/fulfilled/rejected -- do not dispatch these manuallygetDefaultMiddleware() must be called (not referenced) in middleware configRootState from store.getState return type -- keep slice state types accurate</red_flags>
See reference.md for decision frameworks, anti-patterns with code examples, migration guides, and performance considerations.
<critical_reminders>
(You MUST use configureStore for store setup - NEVER legacy createStore)
(You MUST use createSlice for all reducers - NEVER switch statements or manual action creators)
(You MUST define typed hooks (useAppSelector, useAppDispatch) once in a hooks file)
(You MUST use named exports ONLY - NO default exports in any Redux files)
(You MUST use named constants for ALL numbers - NO magic numbers in state code)
Failure to follow these rules will cause type safety issues, unnecessary boilerplate, and convention violations.
</critical_reminders>
development
Material Design component library for Vue 3
development
VitePress 1.x — Vue-powered static site generator for documentation sites, built on Vite
tools
Docusaurus 3.x documentation framework — site configuration, docs/blog plugins, sidebars, versioning, MDX, swizzling, and deployment
development
TanStack Form patterns - useForm, form.Field, validators, arrays, linked fields, createFormHook, type safety