Besharamcode

Integrating Redux Toolkit with React: A Beginner’s Guide

4/11/2025, 6:28:09 PM

Mohit Kushwah

In the ever-evolving world of React development, Redux Toolkit has emerged as the recommended and most efficient way to manage global state. If you’re a beginner looking to integrate Redux Toolkit into your React project, this guide is the perfect starting point. By the end of this blog, you’ll know what Redux Toolkit is, why it matters, and how to implement it step-by-step in a real React app.

What is Redux Toolkit?

Redux Toolkit (RTK) is the official, recommended way to use Redux. It simplifies Redux development by reducing boilerplate code and providing best practices out of the box.

Key Features:

  • Pre-configured store setup
  • Simplified reducers and actions using createSlice
  • Built-in support for redux-thunk
  • Improved developer experience

Why Use Redux Toolkit in React?

Here’s why RTK is ideal for managing state in modern React apps:

  • Less Boilerplate: You no longer need to write action types and creators manually.
  • Easier to Learn: The APIs are intuitive and beginner-friendly.
  • DevTools Support: Works out of the box with Redux DevTools for debugging.
  • Better State Management: Centralizes and organizes state logic efficiently.

Setting Up Redux Toolkit in a React App

Let’s walk through how to set up and use Redux Toolkit in a new or existing React project.

1. Install Required Packages

Run the following command in your project directory:

npm install @reduxjs/toolkit react-redux

2. Create a Redux Slice

Create a new file in your src/features folder:

// src/features/counter/counterSlice.js

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

const initialState = {
  value: 0,
};

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

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

3. Configure the Redux Store

Create the store in a new file:

// src/app/store.js

import { configureStore } from '@reduxjs/toolkit';
import counterReducer from '../features/counter/counterSlice';

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

4. Provide the Store to React

Wrap your main app component with <Provider>:

// src/index.js

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

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

5. Use Redux State in Components

// src/components/Counter.js

import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { increment, decrement } from '../features/counter/counterSlice';

const Counter = () => {
  const count = useSelector((state) => state.counter.value);
  const dispatch = useDispatch();

  return (
    <div>
      <h2>Count: {count}</h2>
      <button onClick={() => dispatch(increment())}>+</button>
      <button onClick={() => dispatch(decrement())}>-</button>
    </div>
  );
};

export default Counter;

That's it!

Pro Tips for Beginners

  • Use the Redux DevTools Extension for better debugging.
  • Keep slice files modular to maintain scalability.
  • Combine RTK with RTK Query for handling API calls in a clean way.

Final Thoughts

Redux Toolkit has transformed how developers work with Redux in React. It’s clean, scalable, and easy to integrate — perfect for both beginners and pros.

By following this beginner’s guide, you’re already on your way to building scalable and maintainable React applications with ease.

Do you want to dive deeper into advanced Redux patterns or RTK Query for API management? Let us know in the comments below!

Blog Visual

Creating a Dark Mode in React with Tailwind v4:

How to Optimize Your React Application for Better Performance:

Leave a Comment

Comments: