Home › React › Redux Toolkit + RTK Query Copilot path instructions

Redux Toolkit + RTK Query Copilot path instructions

Path-specific Copilot instructions for Redux Toolkit: createSlice, typed hooks, RTK Query endpoints with tags, and no legacy Redux patterns.

GitHub CopilotReact

How to use

Save this as .github/instructions/redux.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.github/instructions/redux.instructions.mdDownload  
---
applyTo: "src/**/*.ts,src/**/*.tsx"
description: Redux Toolkit and RTK Query conventions
---

# Redux Toolkit

- Modern Redux only: `configureStore`, `createSlice`, `createAsyncThunk` or RTK Query. No hand-written action types, `switch` reducers, `connect()` or `redux-thunk` setup.
- Store in `src/app/store.ts`; export `RootState` and `AppDispatch` from it. Use typed hooks from `src/app/hooks.ts`: `useAppDispatch = useDispatch.withTypes<AppDispatch>()` and `useAppSelector = useSelector.withTypes<RootState>()`.
- One slice per feature in `src/features/<feature>/<feature>Slice.ts`. "Mutating" code inside reducers is fine (Immer); never mutate state outside a reducer.
- Keep state normalized; use `createEntityAdapter` for collections.
- Selectors live next to the slice. Memoize derived data with `createSelector`; never return a new array from `useAppSelector` without it.
- Server data goes through RTK Query: one `createApi` per backend in `src/services/api.ts` with `fetchBaseQuery`, endpoints added via `injectEndpoints`. Use `providesTags`/`invalidatesTags` instead of manual refetching.
- Use generated hooks (`useGetPostsQuery`, `useAddPostMutation`) and handle `isLoading`, `isError`, `error` in the component.
- Keep non-serializable values (class instances, Dates, Promises) out of state; store ISO strings.

## Tests
Test reducers as pure functions and components with a real store built by a `setupStore(preloadedState)` helper.

More: all React rules · all GitHub Copilot rules

Related rules

React + TypeScript Copilot path instructions

Path-specific Copilot instructions for React 19 + TypeScript .tsx files: components, hooks, accessibility, and tests.

GitHub CopilotReact

React 19 + Vite SPA rules

Cursor rules for React 19 single-page apps on Vite 6+ with TypeScript, hooks, and Vitest.

CursorReact

TanStack Query v5 rules

Cursor rules for TanStack Query v5 in React: query keys, queryOptions, mutations, and cache invalidation.

CursorReact

Zustand state management Cursor rules

Cursor rules for React state with Zustand: small typed stores, selectors, actions in the store, persist and devtools middleware, and testing.

CursorReact

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Next.js Server Actions Copilot path instructions

Path-specific Copilot instructions for Next.js Server Actions and route handlers: validation, auth, and revalidation.

GitHub CopilotNext.js

Get the best new AI prompts every week

One short email a week: the best new prompts and rules for ChatGPT, Claude, Gemini, Midjourney, Cursor and more, plus what changed in the tools. Free, unsubscribe anytime.

Finishes on our newsletter page at beehiiv (opens in a new tab). Or subscribe directly.