Frontend

Redux Setup & Deployment Guide

Predictable global state for React apps with Redux Toolkit – store, slices, async calls and DevTools.

Updated Official documentation ↗

1. Introduction & use cases

Redux keeps your application's shared state in one store. Components read data with selectors and change it only by dispatching actions, which pure reducers handle. This makes state changes predictable, traceable and easy to debug with the Redux DevTools (including time-travel).

Today Redux is written with Redux Toolkit (RTK), the official package that removes most boilerplate: configureStore, createSlice and createAsyncThunk, plus RTK Query for fetching and caching API data. Redux is a client-side library, so deployment is the same as for any React app.

Where it is used

  • Large React apps where many screens share the same data (user, cart, settings)
  • Complex forms, editors and dashboards with undo/history
  • Caching server data with RTK Query instead of hand-written fetch code
  • Apps that need detailed debugging of every state change

2. Prerequisites

You needVersion / notes
Node.jsCurrent LTS release (check with node -v). Download from nodejs.org or install with nvm.
A React projectCreated with Vite – see the ReactJS guide
Redux DevToolsBrowser extension for Chrome/Firefox/Edge
BasicsReact components, props, hooks (useState, useEffect)

3. Local setup

  1. 1Option A: start from the official template

    The Redux team maintains a Vite + TypeScript + Redux Toolkit template with tests already set up.

    BASH
    npx degit reduxjs/redux-templates/packages/vite-template-redux my-redux-app
    cd my-redux-app
    npm install
    npm run dev
  2. 2Option B: add Redux to an existing React app

    Install Redux Toolkit and the React bindings.

    BASH
    npm install @reduxjs/toolkit react-redux
  3. 3Install Redux DevTools

    Add the Redux DevTools extension to your browser. configureStore connects to it automatically in development.

4. Create & run a project

  1. 1Create a slice

    A slice holds the state, reducers and generated action creators for one feature. RTK lets you "mutate" state inside reducers – Immer turns it into safe immutable updates.

    src/features/counter/counterSlice.js
    import { createSlice } from '@reduxjs/toolkit';
    
    const counterSlice = createSlice({
      name: 'counter',
      initialState: { value: 0 },
      reducers: {
        increment: (state) => { state.value += 1; },
        addBy: (state, action) => { state.value += action.payload; },
      },
    });
    
    export const { increment, addBy } = counterSlice.actions;
    export default counterSlice.reducer;
  2. 2Create the store

    Combine the slices in configureStore.

    src/store.js
    import { configureStore } from '@reduxjs/toolkit';
    import counterReducer from './features/counter/counterSlice';
    
    export const store = configureStore({
      reducer: { counter: counterReducer },
    });
  3. 3Provide the store to React

    Wrap the app with <Provider> once, in the entry file.

    src/main.jsx
    import { createRoot } from 'react-dom/client';
    import { Provider } from 'react-redux';
    import { store } from './store';
    import App from './App';
    
    createRoot(document.getElementById('root')).render(
      <Provider store={store}><App /></Provider>
    );
  4. 4Read and update state in a component

    useSelector reads data; useDispatch sends actions.

    src/App.jsx
    import { useSelector, useDispatch } from 'react-redux';
    import { increment, addBy } from './features/counter/counterSlice';
    
    export default function App() {
      const value = useSelector((s) => s.counter.value);
      const dispatch = useDispatch();
      return (
        <main>
          <h1>Count: {value}</h1>
          <button onClick={() => dispatch(increment())}>+1</button>
          <button onClick={() => dispatch(addBy(5))}>+5</button>
        </main>
      );
    }
  5. 5Fetch API data with RTK Query

    RTK Query generates hooks with loading/error state and caching. Add api.reducer and api.middleware to the store.

    src/services/api.js
    import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
    
    export const api = createApi({
      baseQuery: fetchBaseQuery({ baseUrl: import.meta.env.VITE_API_URL }),
      endpoints: (build) => ({
        getUsers: build.query({ query: () => '/users' }),
      }),
    });
    export const { useGetUsersQuery } = api;
    
    // store.js
    // reducer: { counter: counterReducer, [api.reducerPath]: api.reducer },
    // middleware: (getDefault) => getDefault().concat(api.middleware),

✅ When it works you should see output like Figure 1.

5. Development configuration

Environment variables

Redux itself needs no configuration; your API base URL comes from Vite variables (prefix VITE_). These are compiled into the public bundle – do not store secrets.

.env
VITE_API_URL=http://localhost:8000/api

Key dependencies

Package / toolUsed for
@reduxjs/toolkitconfigureStore, createSlice, createAsyncThunk, RTK Query
react-reduxProvider, useSelector, useDispatch
Redux DevTools extensionInspect actions and state, time-travel debugging
vitest + @testing-library/reactTest reducers and connected components

Folder structure

project structure
src/
├── app/
│   └── store.js          # configureStore
├── features/
│   ├── counter/
│   │   ├── counterSlice.js
│   │   └── Counter.jsx
│   └── users/
│       └── usersSlice.js
├── services/
│   └── api.js            # RTK Query
└── main.jsx              # <Provider store={store}>

Essential commands

CommandWhat it does
npm install @reduxjs/toolkit react-reduxAdd Redux to a React project
npm run devDevelop with hot reload (state is kept across edits)
npm testRun reducer/selector tests (template uses Vitest)
npm run buildProduction build in dist/

6. Production deployment

Redux runs inside the browser bundle, so a Redux app is deployed exactly like a React SPA: build static files and serve them with Nginx, a CDN or a static host.

Server & hosting requirements

RequirementRecommendation
ServerAny static file host (Nginx VPS, S3 + CloudFront, Netlify, Vercel)
BuildNode.js LTS in CI or locally
SPA routingFallback to index.html for client-side routes
Domain + SSLDNS A record + Let’s Encrypt

Deployment steps

  1. 1Build

    Production builds drop the DevTools connection automatically (configureStore enables it only outside production unless you set devTools).

    BASH
    npm ci
    npm run build
  2. 2Prepare an Ubuntu server

    Create a VPS (AWS EC2, DigitalOcean, Hostinger VPS, Linode …) with Ubuntu 24.04 LTS, at least 1 vCPU and 1–2 GB RAM. Log in with SSH, update the system and create a non-root user for the app.

    BASH
    ssh root@YOUR_SERVER_IP
    apt update && apt upgrade -y
    adduser deploy
    usermod -aG sudo deploy
    # copy your SSH key to the new user, then log in as deploy
    rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy
    exit
    ssh deploy@YOUR_SERVER_IP
  3. 3Upload `dist/`

    Copy the build to the web root.

    BASH
    rsync -avz --delete dist/ deploy@YOUR_SERVER_IP:/var/www/example.com/
  4. 4Serve the build with Nginx

    Copy the build output to the server and let Nginx serve it. The try_files … /index.html line sends every unknown path to index.html, so client-side routes (React Router, Vue Router) work after a page refresh.

    /etc/nginx/sites-available/example.com
    server {
        listen 80;
        server_name example.com www.example.com;
        root /var/www/example.com;
        index index.html;
    
        location / {
            try_files $uri $uri/ /index.html;
        }
    
        location ~* \.(js|css|png|jpg|jpeg|gif|svg|webp|woff2?)$ {
            expires 30d;
            add_header Cache-Control "public, immutable";
        }
    }
  5. 5Enable the site and reload Nginx

    Link the config into sites-enabled, test it and reload. nginx -t must say syntax is ok before you reload.

    BASH
    sudo apt install -y nginx
    sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl reload nginx
  6. 6Point your domain to the server

    In your domain registrar's DNS panel add an A record for @ (and www) with the server's public IP address. DNS changes usually appear within minutes but can take up to 24–48 hours. Check with dig or an online DNS checker.

    OUTPUT
    # Type  Name  Value              TTL
    # A     @     203.0.113.10       3600
    # A     www   203.0.113.10       3600
    dig +short example.com
  7. 7Add free HTTPS with Let’s Encrypt

    Certbot gets a free SSL certificate, adds it to the Nginx config and redirects HTTP to HTTPS. Certificates renew automatically (a systemd timer runs twice a day); test renewal once with --dry-run.

    BASH
    sudo apt install -y certbot python3-certbot-nginx
    sudo certbot --nginx -d example.com -d www.example.com
    sudo certbot renew --dry-run

🗺 The whole path from your code to the live site is drawn in the deployment diagram.

7. Images & screenshots

Illustrations drawn for this guide from the commands above. Product dashboards change often, so for screens such as cloud consoles follow the step text and the official documentation.

terminal$ npm run dev VITE ready in 389 ms ➜ Local: http://localhost:5173/# Redux DevTools (browser) shows:# counter/increment { value: 1 }# counter/addBy (5) { value: 6 }
Figure 1: terminal output of the sample Redux project (section 4).
1Slices + store2npm run build3dist/ bundle4rsync to server5Nginx + HTTPS
Figure 2: production deployment flow (section 6).
src/├── app/│ └── store.js # configureStore├── features/│ ├── counter/│ │ ├── counterSlice.js│ │ └── Counter.jsx│ └── users/│ └── usersSlice.js├── services/│ └── api.js # RTK Query└── main.jsx # <Provider store={store}>
Figure 3: project folder structure (section 5).

8. Common errors & solutions

could not find react-redux context value; please ensure the component is wrapped in a <Provider>

Wrap the root component with <Provider store={store}> in main.jsx, and make sure tests render components inside a Provider too.

A non-serializable value was detected in the state

Keep only plain data (objects, arrays, strings, numbers) in Redux – not Promises, class instances, DOM nodes or Date objects (store ISO strings instead).

Component does not re-render after dispatch

You returned a new value and mutated, or mutated outside a reducer. Inside createSlice either mutate the draft or return a new object – not both.

useSelector causes re-renders on every update

Return primitive values or memoised selectors (createSelector) instead of building new objects/arrays inside the selector.

RTK Query hook always shows old data after a mutation

Use providesTags on queries and invalidatesTags on mutations so the cache refreshes.

Best practices

  • Put only truly shared state in Redux; keep form input and UI toggles in component state.
  • One slice per feature, colocated with its components ("feature folders").
  • Use RTK Query for server data instead of writing fetch thunks by hand.
  • Write unit tests for reducers – they are pure functions and easy to test.
  • Use TypeScript types RootState and AppDispatch for typed hooks in larger apps.