Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

redux-toolkit

БесплатноБез исполняемых скриптовНе проверен

Redux Toolkit for React state management. Covers slices, thunks, and RTK Query. Use for complex global state. USE WHEN: user mentions "redux", "redux…

claude-dev-suiteот claude-dev-suite★ 51 звезда на GitHub

Об этом скилле

Redux Toolkit Core Knowledge

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: redux-toolkit for comprehensive documentation.

Slice

import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface CounterState {
  value: number;
}

const counterSlice = createSlice({
  name: 'counter',
  initialState: { value: 0 } as CounterState,
  reducers: {
    increment: (state) => { state.value += 1; },
    decrement: (state) => { state.value -= 1; },
    incrementByAmount: (state, action: PayloadAction<number>) => {
      state.value += action.payload;
    },
  },
});

export const { increment, decrement, incrementByAmount } = counterSlice.actions;
export default counterSlice.reducer;

Store Setup

import { configureStore } from '@reduxjs/toolkit';

export const store = configureStore({
  reducer: {
    counter: counterReducer,
    users: usersReducer,
  },
});

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

Async Thunks

import { createAsyncThunk } from '@reduxjs/toolkit';

export const fetchUsers = createAsyncThunk(
  'users/fetchUsers',
  async (_, { rejectWithValue }) => {
    try {
      const response = await api.getUsers();
      return response.data;
    } catch (err) {
      return rejectWithValue(err.message);
    }
  }
);

// In slice
extraReducers: (builder) => {
  builder
    .addCase(fetchUsers.pending, (state) => { state.loading = true; })
    .addCase(fetchUsers.fulfilled, (state, action) => {
      state.loading = false;
      state.users = action.payload;
    })
    .addCase(fetchUsers.rejected, (state, action) => {
      state.loading = false;
      state.error = action.payload;
    });
}

Hooks

import { useSelector, useDispatch } from 'react-redux';
import { RootState, AppDispatch } from './store';

export const useAppDispatch = useDispatch.withTypes<AppDispatch>();
export const useAppSelector = useSelector.withTypes<RootState>();

// Usage
const count = useAppSelector((state) => state.counter.value);
const dispatch = useAppDispatch();
dispatch(increment());

When NOT to Use This Skill

Scenario Use Instead
Simple global state (user prefs, theme) zustand for less boilerplate
Server state management tanstack-query or RTK Query only
Vue 3 applications pinia
Small projects or prototypes React Context + hooks or Zustand
Component-local state React useState/useReducer

Anti-Patterns

Anti-Pattern Why It's Bad Correct Approach
Using plain Redux instead of RTK Massive boilerplate, error-prone Always use Redux Toolkit
Mutating state without Immer Breaks immutability, bugs Use createSlice with Immer built-in
Storing everything in Redux Unnecessary complexity Keep component state local when possible
Not using typed hooks Loses type safety Export typed useAppDispatch/useAppSelector
Fetching data in components with thunks Duplicates request logic Use RTK Query for data fetching
Not using createAsyncThunk Manual loading/error handling Use createAsyncThunk for async actions
Persisting entire state Large localStorage, slow hydration Only persist auth/critical slices
No error handling in thunks Silent failures Use rejectWithValue in thunks
Circular dependencies between slices Hard to maintain, bugs Use middleware or separate selectors
Not normalizing nested data Slow updates, complex reducers Normalize with @reduxjs/toolkit/normalizr

Quick Troubleshooting

Issue Cause Solution
"Cannot read property of undefined" State hydration race condition Add loading checks or use skipHydration
Actions not triggering re-renders Not using typed selectors Use useAppSelector with proper typing
"Invariant violation" in Redux State mutation outside Immer Only mutate in createSlice reducers
Slow performance with large state Non-memoized selectors Use createSelector from Reselect
DevTools not showing actions DevTools disabled in production Set devTools: process.env.NODE_ENV !== 'production'
RTK Query cache not invalidating Missing or wrong tags Add providesTags and invalidatesTags
Serialization errors with persist Non-serializable data in state Add to serializableCheck.ignoredActions
Thunk errors not caught No error boundary Wrap with error boundary or handle in component

Production Readiness

Store Configuration

// store/index.ts - Production-ready store
import { configureStore, combineReducers } from '@reduxjs/toolkit';
import { setupListeners } from '@reduxjs/toolkit/query';
import {
  persistStore,
  persistReducer,
  FLUSH,
  REHYDRATE,
  PAUSE,
  PERSIST,
  PURGE,
  REGISTER,
}
Полный SKILL.md на GitHub

Установить redux-toolkit в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Grep
Glob
Write
Edit

Вложенные файлы

quick-ref/rtk-query.mdquick-ref/slices.md

FAQ

Что делает скилл redux-toolkit?

Redux Toolkit for React state management. Covers slices, thunks, and RTK Query. Use for complex global state. USE WHEN: user mentions "redux", "redux toolkit", "RTK", "createSlice", asks about "complex state management", "time-travel debugging", "middleware", "thunks", "RTK Query", "global state with DevTools", "enterprise state management" DO NOT USE FOR: simple state - use `zustand`; server data - prefer `tanstack-query`; Vue apps - use `pinia`; small projects - overhead not justified

Как установить скилл redux-toolkit?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл redux-toolkit запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить redux-toolkit с