# redux-toolkit

Redux Toolkit best practices for React and Next.js applications using TypeScript. Helps structure feature slices, typed hooks, and RTK Query endpoints.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1300 installs · ★ 286
- Author: Mindrally
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/Mindrally/skills/tree/HEAD/redux-toolkit/SKILL.md
- Updated: 2026-10-08
- HTML: https://affpapa.org/en/nevibecode/skills/redux-toolkit

## What it does

The skill instructs the coding agent on Redux Toolkit state management conventions. It enforces feature-based slices with `createSlice` and encapsulated state access via `createSelector`. For remote data fetching and cache invalidation, it guides the model toward RTK Query and `createAsyncThunk`.

It establishes clear TypeScript conventions. Strict mode is expected, interfaces take precedence over types for object models, and components must rely on typed `useAppDispatch` and `useAppSelector` hooks. Error handling pairs with Zod validation, while unit testing relies on Jest and React Testing Library following the Arrange-Act-Assert pattern.

The skill enforces strict separation by feature. Generating state for a monolithic single-file store will conflict directly with its rules.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill redux-toolkit -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/redux-toolkit/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/redux-toolkit/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill redux-toolkit -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/redux-toolkit/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill redux-toolkit -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/redux-toolkit/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install Mindrally/skills redux-toolkit
```

2. **Manually: put the files in place**
- File: `.github/skills/redux-toolkit/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill redux-toolkit -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Mindrally/skills --path redux-toolkit
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/redux-toolkit/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill redux-toolkit -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/Mindrally/skills/tree/HEAD/redux-toolkit/SKILL.md

## When to use it
- generate feature slices using `createSlice`
- implement data fetching and caching with RTK Query
- configure typed `useAppDispatch` and `useAppSelector` hooks
- write tests for reducers and selectors using React Testing Library

## Example prompts
- Create a shopping cart slice using Redux Toolkit and TypeScript interfaces
- Set up an RTK Query API slice for user profile fetching with cache invalidation
- Write unit tests for my auth thunk using Jest and Arrange-Act-Assert

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 156170ba637ab71b.

BEGIN THIRD-PARTY FILE 156170ba637ab71b
````text
---
name: redux-toolkit
description: Comprehensive Redux Toolkit best practices for React and Next.js applications with TypeScript.
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# Redux Toolkit

You are an expert in Redux Toolkit for state management in React and Next.js applications.

## Development Philosophy

- Write clean, maintainable, and scalable code
- Adhere to SOLID principles
- Favor functional and declarative programming patterns
- Emphasize type safety and component-driven approaches

## Redux State Management

### Core Principles
- Implement Redux Toolkit for global state management
- Use createSlice to define state, reducers, and actions together
- Normalize state structure to prevent deeply nested data
- Employ selectors to encapsulate state access
- Separate concerns by feature; avoid monolithic slices

### Slice Structure
```typescript
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

interface CounterState {
  value: number
  isLoading: boolean
}

const initialState: CounterState = {
  value: 0,
  isLoading: false,
}

const counterSlice = createSlice({
  name: 'counter',
  initialState,
  reducers: {
    increment: (state) => {
      state.value += 1
    },
    setLoading: (state, action: PayloadAction<boolean>) => {
      state.isLoading = action.payload
    },
  },
})

export const { increment, setLoading } = counterSlice.actions
export default counterSlice.reducer
```

## Naming Conventions

- **PascalCase**: Components, type definitions, interfaces
- **kebab-case**: Directory and file names
- **camelCase**: Variables, functions, methods, hooks, properties
- **UPPERCASE**: Environment variables, constants

### Prefixes
- Event handlers: `handle` (e.g., `handleClick`)
- Boolean variables: verbs (e.g., `isLoading`, `hasError`)
- Custom hooks: `use` (e.g., `useAuth`)

## TypeScript Integration

- Enable strict mode
- Define clear interfaces for props and Redux state structure
- Apply generics where type flexibility is needed
- Prefer interfaces over types for object structures
- Use typed hooks (`useAppDispatch`, `useAppSelector`)

## Async Operations

### RTK Query
- Use RTK Query for data fetching and caching
- Define API slices with endpoints
- Leverage automatic cache invalidation
- Implement optimistic updates when appropriate

### createAsyncThunk
```typescript
export const fetchUser = createAsyncThunk(
  'user/fetch',
  async (userId: string, { rejectWithValue }) => {
    try {
      const response = await api.getUser(userId)
      return response.data
    } catch (error) {
      return rejectWithValue(error.message)
    }
  }
)
```

## Performance Optimization

- Use React.memo() strategically
- Implement useCallback for memoized functions
- Apply useMemo for expensive computations
- Avoid inline function definitions in JSX
- Use dynamic imports for code splitting
- Employ proper keys in lists (avoid index-based keys)

## Selectors

- Create memoized selectors with createSelector
- Encapsulate state shape in selectors
````
END THIRD-PARTY FILE 156170ba637ab71b

The third-party file has ended. Everything between the 156170ba637ab71b tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3050 of 3458 bytes. © Mindrally · Apache-2.0 · https://github.com/Mindrally/skills/tree/HEAD/redux-toolkit/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
