Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Redux Toolkit createSlice best practices
.claude/skills/ledgerhq-redux-slice/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | -10% | 0% |
| case-02 | ✗→✓ | ▲ Improved | -4% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 81% | 0% |
| case-06 | ✓→✓ | = Same ✓ | 17% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 21% | 0% |
name for action type prefixesinitialState with satisfiestypescript// ✅ GOOD import { createSlice, PayloadAction } from "@reduxjs/toolkit"; interface MyState { value: number; status: "idle" | "loading" | "error"; } const initialState: MyState = { value: 0, status: "idle", }; const mySlice = createSlice({ name: "myFeature", initialState, reducers: { setValue: (state, action: PayloadAction<number>) => { state.value = action.payload; }, setStatus: (state, action: PayloadAction<MyState["status"]>) => { state.status = action.payload; }, }, }); export const { setValue, setStatus } = mySlice.actions; export default mySlice.reducer;
Add the slice to reducers/index.ts:
typescript// 1. Import the reducer and state type import myFeature, { MyFeatureState } from "./myFeature"; // 2. Add to State type export type State = { // ...existing myFeature: MyFeatureState; }; // 3. Add to combineReducers const appReducer = combineReducers({ // ...existing myFeature, });
PayloadAction<T> for actions with payloadscreateSelector for derived datatypescript// Colocate selectors with slice export const selectValue = (state: RootState) => state.myFeature.value; export const selectStatus = (state: RootState) => state.myFeature.status;
typescriptextraReducers: (builder) => { builder .addCase(fetchData.pending, (state) => { state.status = "loading"; }) .addCase(fetchData.fulfilled, (state, action) => { state.status = "idle"; state.data = action.payload; }) .addCase(fetchData.rejected, (state) => { state.status = "error"; }); },
Other measured skills in the registry, with their headline benchmark lift.