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.
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:
Here’s why RTK is ideal for managing state in modern React apps:
Let’s walk through how to set up and use Redux Toolkit in a new or existing React project.
Run the following command in your project directory:
npm install @reduxjs/toolkit react-redux
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;
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,
},
});
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>
);
// 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!
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!