Home
Daily
The Modern Way to Manage State in React
November 02, 2025
1 min

Table Of Contents

01
🧠 What is Redux Toolkit?
02
⚙️ Why Redux Toolkit?
03
Redux Data Flow Diagram
04
🧩 The Core Building Blocks
05
🧠 How It All Fits Together in React
06
🔥 Final Thoughts

If you’ve ever tried to manage global state in a large React app, you’ve probably felt the pain of boilerplate, complexity, and confusion that traditional Redux brought.

But those days are gone. Say hello to Redux Toolkit (RTK) — the official, modern, and clean approach to writing Redux logic.


🧠 What is Redux Toolkit?

Redux Toolkit (RTK) is the official, recommended way to write Redux code. It’s a package that simplifies Redux setup and helps you write cleaner, more efficient, and less error-prone state management.

Instead of manually creating actions, reducers, and types — RTK gives you elegant utilities that do the heavy lifting for you.

It’s like upgrading from a manual car to an automatic — same power, less stress.


⚙️ Why Redux Toolkit?

Here’s why most modern React developers have switched to RTK:

Less Boilerplate: No more writing endless action types or switch statements.

Built-in Immer: You can write mutable-looking code (state.value += 1), and RTK handles immutability under the hood.

Powerful Async Support: Handle API calls easily with createAsyncThunk.

Clean Architecture: Slices organize logic by feature, not by file type.

Easy Integration: Works perfectly with TypeScript, React hooks, and Redux DevTools.


Redux Data Flow Diagram

+-------------+ +-------------+ +-------------+
| UI Event | -----> | Action | -----> | Reducer |
| (dispatch) | | (Intent) | | (Logic) |
+-------------+ +-------------+ +-------------+
^ |
| v
+------------------- Store ------------------+
(Global State)

🧩 The Core Building Blocks

Let’s break down the main pieces of Redux Toolkit.

1️⃣ configureStore

Creates the Redux store with sensible defaults — including DevTools and middleware preconfigured.

import { configureStore } from '@reduxjs/toolkit';
import counterReducer from './features/counter/counterSlice';
export const store = configureStore({
reducer: {
counter: counterReducer,
},
});

Simple. No more manual createStore, combineReducers, or thunk setup.


2️⃣ createSlice

Defines state, reducers, and actions in one clean place.

import { createSlice } from '@reduxjs/toolkit';
const counterSlice = createSlice({
name: 'counter',
initialState: { value: 0 },
reducers: {
increment: (state) => { state.value += 1 },
decrement: (state) => { state.value -= 1 },
reset: (state) => { state.value = 0 }
}
});
export const { increment, decrement, reset } = counterSlice.actions;
export default counterSlice.reducer;

Boom 💥 — one slice file replaces what used to be three different files in classic Redux.


3️⃣ createAsyncThunk

Simplifies handling async actions like API calls.

import { createAsyncThunk } from '@reduxjs/toolkit';
export const fetchPokemons = createAsyncThunk(
'pokemon/fetchPokemons',
async () => {
const res = await fetch('https://pokeapi.co/api/v2/pokemon?limit=10');
return await res.json();
}
);

RTK automatically generates pending, fulfilled, and rejected action types — all ready to handle in your slice.


4️⃣ Handling Async State in a Slice

Combine it with extraReducers:

import { createSlice } from '@reduxjs/toolkit';
import { fetchPokemons } from './pokemonThunks';
const pokemonSlice = createSlice({
name: 'pokemon',
initialState: { list: [], status: 'idle', error: null },
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchPokemons.pending, (state) => {
state.status = 'loading';
})
.addCase(fetchPokemons.fulfilled, (state, action) => {
state.status = 'succeeded';
state.list = action.payload.results;
})
.addCase(fetchPokemons.rejected, (state, action) => {
state.status = 'failed';
state.error = action.error.message;
});
},
});
export default pokemonSlice.reducer;

Now your UI can easily reflect loading, success, or error states.


🧠 How It All Fits Together in React

Once your store and slices are ready:

import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { increment } from './counterSlice';
function Counter() {
const count = useSelector((state) => state.counter.value);
const dispatch = useDispatch();
return (
<div>
<h1>Count: {count}</h1>
<button onClick={() => dispatch(increment())}>Increment</button>
</div>
);
}

And wrap your app with <Provider store={store}> in index.js.


🔥 Final Thoughts

Redux Toolkit is Redux done right. It keeps all the benefits — predictable state, time-travel debugging, DevTools — but removes all the noise.

If you’re starting a new React project today, RTK should be your default choice for state management.

Whether you’re building a simple counter or a full-featured Pokémon app 🐉, Redux Toolkit helps you stay clean, scalable, and modern.


Tags

#redux

Share

Related Posts

Redux Toolkit
🚀 CI/CD: The Engine Behind Modern Software Delivery
December 13, 2025
2 min
© 2025, All Rights Reserved.
Powered By

Social Media

githublinkedinyoutube