/cursor-tutorials

How to generate Redux Toolkit code with Cursor

Learn how to generate Redux Toolkit code with Cursor using fast, automated workflows to boost productivity and streamline your development process.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to generate Redux Toolkit code with Cursor

You generate Redux Toolkit code in Cursor the same way working developers do: you create the files you need, then use Cursor’s AI (either the Chat, Cmd+K inline actions, or Composer) to scaffold slices, thunks, and store setup. Cursor won’t magically “host” Redux or auto‑wire your project — it edits files in your local React app. The real workflow is: you tell Cursor exactly what slice you want, where it should live, and what reducers or async logic it should generate. Then you check every diff before accepting it.

 

What Redux Toolkit (RTK) Code You Usually Generate

 

Redux Toolkit gives you a simpler way to manage app state. Instead of writing reducers by hand, RTK gives you helper functions:

  • createSlice – generates a reducer + actions for a chunk of state.
  • createAsyncThunk – handles async operations like API calls.
  • configureStore – sets up the Redux store with sane defaults.

Cursor can generate all of these for you if you describe them clearly.

 

How to Generate RTK Code with Cursor

 

Below is the real, practical workflow that developers actually use inside Cursor:

  • Create a file such as src/features/todos/todosSlice.js (or .ts if using TypeScript).
  • Open Cmd+K inside that empty file and type a prompt like: “Create a Redux Toolkit slice named todosSlice with an array of todos, actions to add and toggle todos, and an async thunk that loads todos from /api/todos.”
  • Cursor will generate the code directly in that file and show a diff you can inspect.
  • If Cursor misses anything, highlight the block of code and write in Chat: “Refactor this to use TypeScript” or “Add loading/error state for the thunk.”
  • Use Composer if you need multi-file updates (for example: generate slice, store, typed hooks, and update App.jsx imports).

 

A Real Working Example You Can Generate with Cursor

 

This is the kind of code Cursor will output if prompted correctly. It must live in your real React project, usually in src/features/example.

// src/features/todos/todosSlice.js

import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'

// Async thunk for loading todos
export const fetchTodos = createAsyncThunk(
  'todos/fetchTodos',
  async () => {
    const res = await fetch('/api/todos') // example API endpoint
    return res.json()
  }
)

const todosSlice = createSlice({
  name: 'todos',
  initialState: {
    items: [],
    loading: false,
    error: null
  },
  reducers: {
    addTodo(state, action) {
      state.items.push(action.payload) // RTK uses Immer so this is valid
    },
    toggleTodo(state, action) {
      const todo = state.items.find(t => t.id === action.payload)
      if (todo) todo.completed = !todo.completed
    }
  },
  extraReducers: builder => {
    builder
      .addCase(fetchTodos.pending, state => {
        state.loading = true
        state.error = null
      })
      .addCase(fetchTodos.fulfilled, (state, action) => {
        state.loading = false
        state.items = action.payload
      })
      .addCase(fetchTodos.rejected, (state, action) => {
        state.loading = false
        state.error = action.error.message
      })
  }
})

export const { addTodo, toggleTodo } = todosSlice.actions
export default todosSlice.reducer

 

Configure the Redux Store

 

Cursor can generate this too. Put it in src/store.js and tell Cursor to import your slice reducer.

// src/store.js

import { configureStore } from '@reduxjs/toolkit'
import todosReducer from './features/todos/todosSlice'

export const store = configureStore({
  reducer: {
    todos: todosReducer
  }
})

 

Wrap Your App in the Provider

 

This part you do once. Cursor can patch src/main.jsx or src/index.js for you.

// src/main.jsx

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import { Provider } from 'react-redux'
import { store } from './store'

ReactDOM.createRoot(document.getElementById('root')).render(
  <Provider store={store}>
    <App />
  </Provider>
)

 

How to Prompt Cursor Effectively

 

When generating Redux Toolkit code, Cursor responds best to clear, file-specific instructions:

  • “In this file, generate a complete Redux Toolkit slice for authentication with login/logout actions and an async login thunk.”
  • “Add selectors for filtered todos and incomplete todos.”
  • “Update store.js to include the new slice.”
  • “Refactor this slice to TypeScript and strictly type state + thunks.”

This makes Cursor produce accurate, real-world code instead of guessing.

 

Practical Tips So Cursor Doesn’t Hallucinate

 

  • Always create the file yourself first. Don’t let Cursor guess filenames.
  • Keep prompts scoped to the file when possible.
  • Use Composer only when you truly need changes in multiple files.
  • Check every diff. Never accept large edits blindly.
  • Give Cursor your project structure if it doesn’t know where to put things.

This keeps your Redux Toolkit setup clean, predictable, and production‑safe.

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022