<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raj kumar Sailla on Medium]]></title>
        <description><![CDATA[Stories by Raj kumar Sailla on Medium]]></description>
        <link>https://medium.com/@saillarajkumar2297?source=rss-2ddbf2b96dca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XSdDb18y-XECApCa</url>
            <title>Stories by Raj kumar Sailla on Medium</title>
            <link>https://medium.com/@saillarajkumar2297?source=rss-2ddbf2b96dca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 15:03:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saillarajkumar2297/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why I Switched from Redux to Redux Toolkit (RTK) — And How You Can Too]]></title>
            <link>https://medium.com/@saillarajkumar2297/why-i-switched-from-redux-to-redux-toolkit-rtk-and-how-you-can-too-4da8e406362b?source=rss-2ddbf2b96dca------2</link>
            <guid isPermaLink="false">https://medium.com/p/4da8e406362b</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <dc:creator><![CDATA[Raj kumar Sailla]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 05:52:16 GMT</pubDate>
            <atom:updated>2025-06-30T09:13:32.800Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why I Switched from Redux to Redux Toolkit (RTK) — And How You Can Too</h3><p>If you’ve worked on a large-scale React application, you’ve likely encountered <strong>Redux</strong>, a powerful state management library. However, if you’re like me, you may have quickly realized that setting up Redux the traditional way can feel like a chore.</p><p>That’s where <strong>Redux Toolkit (RTK)</strong> comes in — the <strong>standard</strong> way to write Redux logic today.</p><h3>Understanding the Redux Data Flow</h3><p>Before jumping into Redux Toolkit, it’s important to understand how Redux works under the hood. Here’s the typical flow:</p><h3><strong>dispatch(action) → reducer → store → component (via selector)</strong></h3><ul><li><strong>Dispatch</strong>: You trigger actions using dispatch(action).</li><li><strong>Reducer</strong>: The reducer receives the action and updates the state accordingly.</li><li><strong>Store</strong>: The Redux store holds the entire state tree.</li><li><strong>Selector</strong>: Components subscribe to the specific slice of state they need using useSelector.</li></ul><p>The store can be split into multiple <strong>slices</strong>, such as cart, user, products, etc. Each slice manages a specific part of the global state.</p><p>This flow ensures that state updates are predictable and centralized.</p><h3>Why I Switched from Redux to Redux Toolkit</h3><p>After using plain Redux in several projects, I found myself asking: <em>Why does this have to be so complicated?</em> Here are a few reasons why I moved to Redux Toolkit:</p><h3>1. Complex Store Configuration</h3><p>Setting up a Redux store manually means wiring reducers, middleware, and DevTools yourself — not beginner-friendly at all.</p><h3>2. Too Many Packages</h3><p>With plain Redux, you often need to install multiple libraries like redux, react-redux, redux-thunk, and redux-devtools-extension. That’s a lot of dependencies for just managing state.</p><h3>3. Too Much Boilerplate</h3><p>Writing action types, action creators, and switch-case reducers felt repetitive and bloated.</p><p>Redux Toolkit addresses all of these problems and provides a clean, modern way to write Redux logic with less code.</p><h3>What Is Redux Anyway?</h3><p>Before diving into Redux Toolkit, let’s briefly revisit what Redux is. Redux is a <strong>state management library</strong> for JavaScript applications. It helps you predictably manage global state using actions, reducers, and a single store. While Redux is powerful, it’s not always necessary — it’s best suited for <strong>large-scale applications</strong> with complex state interactions.</p><h3>Getting Started with Redux Toolkit</h3><p>Let’s walk through a simple example: a <strong>shopping cart</strong> where you can add or remove items.</p><h3>1. Installation</h3><p>To get started, install the necessary packages:</p><p>npm install <a href="http://twitter.com/reduxjs/toolkit">@reduxjs/toolkit</a><br>npm install react-redux</p><h3>2. Project Structure</h3><p>Create a folder named redux (or store, depending on your convention). Inside that, create the following files:</p><p>redux/<br> ├── applicationStore.js<br> └── cartSlice.js</p><h3>Creating a Cart Slice</h3><p>In cartSlice.jsWe define the cart state and actions using createSlice:</p><pre>// redux/cartSlice.js<br>import { createSlice } from &quot;@reduxjs/toolkit&quot;;<br>const cartSlice = createSlice({<br>  name: &quot;cart&quot;,<br>  initialState: {<br>    items: [],<br>  },<br>  reducers: {<br>    addItem: (state, action) =&gt; {<br>      state.items.push(action.payload);<br>    },<br>    removeItem: (state, action) =&gt; {<br>      state.items = state.items.filter((item) =&gt; item.id !== action.payload.id);<br>    },<br>  },<br>});<br>export const { addItem, removeItem } = cartSlice.actions;<br>export default cartSlice.reducer;</pre><h3>Setting Up the Store</h3><p>Now let’s configure the Redux store using configureStore from RTK.</p><pre>// redux/applicationStore.js<br>import { configureStore } from &quot;@reduxjs/toolkit&quot;;<br>import cartReducer from &quot;./cartSlice&quot;;<br>const store = configureStore({<br>  reducer: {<br>    cart: cartReducer,<br>  },<br>});<br>export default store;</pre><h3>Wait — Where is cartReducer Coming From?</h3><p>This is a common point of confusion.</p><ul><li>cartReducer It&#39;s <strong>just a name</strong> you&#39;re assigning to the default export from cartSlice.js.</li><li>That default export is actually the <strong>reducer function</strong> generated by createSlice.</li><li>When you write import cartReducer from &quot;./cartSlice&quot;You’re importing that reducer directly.</li></ul><p>You could rename it to anything — for example:</p><pre>import myCoolReducer from &quot;./cartSlice&quot;;</pre><p>…and it would still work, as long as you plug it into the store like this:</p><pre>reducer: {<br>  cart: myCoolReducer,<br>}</pre><p>Even though there’s no variable literally named cartReducer inside cartSlice.jsIt works because you exported cartSlice.reducer as the default export.</p><h3>Integrating Redux in Your React App</h3><p>Wrap your application with the Provider from react-redux in index.js or App.js:</p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom&quot;;<br>import App from &quot;./App&quot;;<br>import { Provider } from &quot;react-redux&quot;;<br>import store from &quot;./redux/applicationStore&quot;;<br>ReactDOM.render(<br>  &lt;Provider store={store}&gt;<br>     &lt;App /&gt; <br>  &lt;/Provider&gt;,<br>  document.getElementById(&quot;root&quot;)<br>);</pre><h3>Using Redux Toolkit in Components</h3><p>Here’s how to dispatch actions and read data from the Redux store:</p><pre>import { useDispatch, useSelector } from &quot;react-redux&quot;;<br>import { addItem, removeItem } from &quot;./redux/cartSlice&quot;;<br>const CartComponent = () =&gt; {<br>  const dispatch = useDispatch();<br>  const cartItems = useSelector((state) =&gt; state.cart.items);<br>  const handleAddToCart = (item) =&gt; {<br>    dispatch(addItem(item));<br>  };<br>  const handleRemoveFromCart = (item) =&gt; {<br>    dispatch(removeItem(item));<br>  };<br>  return (<br>    &lt;div&gt;<br>       &lt;h2&gt;Cart&lt;/h2&gt; <br>      {cartItems.map((item) =&gt; (<br>        &lt;div key={item.id}&gt;<br>           {item.name} <br>          &lt;button onClick={() =&gt; handleRemoveFromCart(item)}&gt;Remove&lt;/button&gt; <br>        &lt;/div&gt;<br>      ))}<br>       <br>    &lt;/div&gt;<br>  );<br>};</pre><h3>What If We Have Multiple Slices?</h3><p>You might have more than one slice in a large application — like cartSlice, userSlice, productSlice, etc. Each manages a different piece of your Redux state.</p><p>Here’s how you add them to your store:</p><pre>import { configureStore } from &quot;@reduxjs/toolkit&quot;;<br>import cartReducer from &quot;./cartSlice&quot;;<br>import userReducer from &quot;./userSlice&quot;;<br><br>const store = configureStore({<br>  reducer: {<br>    cart: cartReducer,<br>    user: userReducer,<br>  },<br>});</pre><p>And in your component, access them like this:</p><pre>const cartItems = useSelector((state) =&gt; state.cart.items);<br>const userName = useSelector((state) =&gt; state.user.name);</pre><p>Each slice still has its own actions and reducer logic, but you keep them modular and clean.</p><h3>Final Thoughts</h3><p>Redux Toolkit has completely changed the way I write Redux code. It’s more concise, easier to understand, and comes with built-in tools that make development much smoother.</p><p>If you’re still using plain Redux in your projects, I highly recommend giving RTK a try — it’s the modern way forward.</p><p><em>Thanks for reading! If you found this article helpful, consider sharing it with your fellow developers or dropping a comment below. Happy coding!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4da8e406362b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>