<?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 Mehmet Arı on Medium]]></title>
        <description><![CDATA[Stories by Mehmet Arı on Medium]]></description>
        <link>https://medium.com/@mehmetarii?source=rss-fe679ccc3132------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9iWU0sx_FNN0UDPXTuGUcw.jpeg</url>
            <title>Stories by Mehmet Arı on Medium</title>
            <link>https://medium.com/@mehmetarii?source=rss-fe679ccc3132------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:06:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mehmetarii/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[Making Redux Simple]]></title>
            <link>https://medium.com/@mehmetarii/making-redux-simple-45b95aef72ce?source=rss-fe679ccc3132------2</link>
            <guid isPermaLink="false">https://medium.com/p/45b95aef72ce</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <dc:creator><![CDATA[Mehmet Arı]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 22:31:44 GMT</pubDate>
            <atom:updated>2025-09-16T22:32:35.697Z</atom:updated>
            <content:encoded><![CDATA[<p>When people hear “<strong>Redux</strong>,” many imagine complex structures and long, incomprehensible boilerplate code. Especially with traditional Redux, having to create separate files for everything and writing actions and reducers one by one intimidated developers.</p><p>However, modern Redux (<strong>Redux Toolkit</strong>) has completely changed this perception. Now, we write less code and can manage state easily with a well-organized file structure. In this article, I will explain <strong>why Redux exists,</strong> <strong>its fundamental logic </strong>and<strong> how it’s not as difficult as it seems.</strong></p><h3>Why Does Redux Exist?</h3><p>One of the biggest challenges when working with React is <strong>state management</strong>.</p><p>For small projects, <strong><em>useState</em></strong> or <strong><em>useContext</em></strong> is often sufficient. However, as the project grows, certain problems begin to emerge:</p><ul><li>Many components need access to the same data (for example, user information, theme settings, or language preference).</li><li>Keeping the data up-to-date becomes difficult.</li><li>The state flow becomes complex, making it difficult to track which component is updating which piece of data.</li></ul><p><strong>Think of it this way:</strong></p><p>Imagine a company where everyone keeps a separate customer list on their own computer. It would be difficult to access up-to-date information. But if all the information is stored in a single “central database,” everyone can look at the same current list. Redux works just like this central database.</p><h3>The Core Concept of Redux</h3><p>Redux is built on three core concepts:</p><ul><li><strong>Store</strong> =&gt; A centralized store that holds the entire state of the application.</li><li><strong>Reducer</strong> =&gt; Functions that define how the state should be updated.</li><li><strong>Action</strong> =&gt; An event triggered by the user or the system.</li></ul><p>At this point, it’s important to understand the following two concepts we encounter when using React with Redux:</p><ul><li><strong>dispatch</strong> =&gt; It is used to trigger an action.<br> Example: When a user wants to increment a counter, <strong><em>dispatch(increment())</em></strong> is called.</li><li><strong>selector</strong> =&gt; It is used to read state from the store.<br> Example: We get the current value of the counter with<strong><em> const count = useAppSelector(state =&gt; state.counter.value)</em></strong> .</li></ul><p>Data flows in a <strong>one-way direction</strong>:</p><ol><li>The user clicks a button,</li><li>An <strong>action</strong> is triggered,</li><li>The corresponding <strong>reducer</strong> updates the state based on this action,</li><li>The <strong>store</strong> is updated, and the React UI re-renders.</li></ol><p>This can be summarized with the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yYkitaR24SuFNXYyTxL1xA.gif" /><figcaption>Redux Data Flow</figcaption></figure><h3>A Simple Counter Example:</h3><p>To show that Redux isn’t that complicated, let’s create an <strong>increment/decrement (counter)</strong> example.</p><h4>Setup:</h4><pre>npm install @reduxjs/toolkit react-redux</pre><h4>File Structure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*8zfgve8Pe_oNCbYJGMOySg.png" /><figcaption>Counter Example File Structure</figcaption></figure><h4>store.ts</h4><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import { TypedUseSelectorHook, useDispatch, useSelector } from &#39;react-redux&#39;;<br>import counterReducer from &#39;../features/counter/counterSlice&#39;;<br><br>// Creating the Store<br>export const store = configureStore({<br>  reducer: {<br>    counter: counterReducer,<br>  },<br>});<br><br>// TypeScript types<br>export type RootState = ReturnType&lt;typeof store.getState&gt;;<br>export type AppDispatch = typeof store.dispatch;<br><br>// Type-Safe selector and dispatch<br>export const useAppSelector: TypedUseSelectorHook&lt;RootState&gt; = useSelector;<br>export const useAppDispatch = () =&gt; useDispatch&lt;AppDispatch&gt;();</pre><h4><strong>counterSlice.ts</strong></h4><pre>import { createSlice, PayloadAction } from &#39;@reduxjs/toolkit&#39;;<br><br>interface CounterState {<br>  value: number;<br>}<br><br>const initialState: CounterState = { value: 0 };<br><br>const counterSlice = createSlice({<br>  name: &#39;counter&#39;,<br>  initialState,<br>  reducers: {<br>    increment: (state) =&gt; { state.value += 1 },<br>    decrement: (state) =&gt; { state.value -= 1 },<br>    incrementByAmount: (state, action: PayloadAction&lt;number&gt;) =&gt; {<br>      state.value += action.payload;<br>    },<br>  },<br>});<br><br>export const { increment, decrement, incrementByAmount } = counterSlice.actions;<br>export default counterSlice.reducer;</pre><h4>App.tsx</h4><pre>import React from &quot;react&quot;;<br>import { useAppSelector, useAppDispatch } from &quot;./app/store&quot;;<br>import { increment, decrement } from &quot;./features/counter/counterSlice&quot;;<br><br>const App: React.FC = () =&gt; {<br>  const count = useAppSelector((state) =&gt; state.counter.value); // Type-safe selector<br>  const dispatch = useAppDispatch(); // Type-safe dispatch<br><br>  return (<br>    &lt;div style={{ textAlign: &quot;center&quot;, marginTop: &quot;50px&quot; }}&gt;<br>      &lt;h1&gt;Increment-Decrement Counter&lt;/h1&gt;<br>      &lt;h2&gt;{count}&lt;/h2&gt;<br>      &lt;button onClick={() =&gt; dispatch(decrement())}&gt;Decrement&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch(increment())}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default App;</pre><h4>main.tsx</h4><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom/client&quot;;<br>import { Provider } from &quot;react-redux&quot;;<br>import { store } from &quot;./app/store&quot;;<br>import App from &quot;./app&quot;;<br><br>ReactDOM.createRoot(document.getElementById(&quot;root&quot;) as HTMLElement).render(<br>  &lt;React.StrictMode&gt;<br>    &lt;Provider store={store}&gt;<br>      &lt;App /&gt;<br>    &lt;/Provider&gt;<br>  &lt;/React.StrictMode&gt;<br>);</pre><h3>When Should You Use Redux?</h3><p>It’s not necessary to add Redux to every project.</p><p><strong>For small projects:</strong> <strong><em>useState </em></strong>or <strong><em>Context </em></strong>is sufficient.</p><p><strong>For medium/large projects:</strong> Redux provides great convenience for managing global state such as user sessions, themes, task lists, and notifications.</p><h3>Conclusion</h3><p>Redux, when properly understood, is not complex; <strong>it is an organized tool for state management.</strong><br> Thanks to Redux Toolkit:</p><p><strong>1.</strong> We write less code,<br> <strong>2.</strong> The file structure becomes organized,<br> <strong>3.</strong> State management becomes easier.</p><p>You can explore Redux in more detail through the following official resources:</p><ul><li><a href="https://redux.js.org/tutorials/typescript-quick-start">TypeScript Quick Start | Redux</a></li><li><a href="https://redux.js.org/usage/usage-with-typescript">Usage With TypeScript | Redux</a></li><li><a href="https://redux.js.org/tutorials/essentials/part-1-overview-concepts">Redux Essentials, Part 1: Redux Overview and Concepts | Redux</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45b95aef72ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>