Skip to content

EmanuProds/dotfiles / skills/build-modern-redux-apps-modern-redux

build-modern-redux-apps/modern-redux"

Verified

Use this when setting up a new Redux Toolkit app or modernizing an existing React + Redux codebase. Covers configureStore, Provider wiring, typed hooks, hooks-first React-Redux usage, feature folders, and the correct store lifetime for SPA and SSR-heavy React environments.

FileKindSize
SKILL.mdskill md7.5 KB
references/store-lifetime.mdmarkdown1.9 KB

references/store-lifetime.md

View on GitHub
# Store Lifetime

## Decision table

| Environment                | Default store shape                     | Why                                                                                                  |
| -------------------------- | --------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| Client-only SPA            | One module-level singleton store        | There is one browser session and no cross-request leakage risk.                                      |
| SSR-heavy React app        | `makeStore()` plus provider-local state | Each request needs its own store instance, but that instance must stay stable across client renders. |
| Non-React integration code | Direct store access can be acceptable   | This is outside the React context boundary and should stay out of UI components.                     |

## SPA pattern

```ts
import { configureStore } from '@reduxjs/toolkit'
import { postsSlice } from '../features/posts/postsSlice'

export const store = configureStore({
  reducer: {
    posts: postsSlice.reducer,
  },
})
```

Use this for classic browser SPAs.

## SSR-heavy React pattern

```tsx
// file: src/lib/store.ts
import { configureStore } from '@reduxjs/toolkit'
import { postsSlice } from '../features/posts/postsSlice'

export const makeStore = () =>
  configureStore({
    reducer: {
      posts: postsSlice.reducer,
    },
  })

// file: src/app/StoreProvider.tsx
;('use client')

import { useState, type ReactNode } from 'react'
import { Provider } from 'react-redux'
import { makeStore } from '../lib/store'

export function StoreProvider({ children }: { children: ReactNode }) {
  const [store] = useState(makeStore)
  return <Provider store={store}>{children}</Provider>
}
```

Create the store per request, then keep it stable inside the provider component.
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 323kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 323kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 323kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 323kUpdated Claude CodeCodexVerifiedInstall