<?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 Christian on Medium]]></title>
        <description><![CDATA[Stories by Christian on Medium]]></description>
        <link>https://medium.com/@christiannaths?source=rss-47e4506a980d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fe4WKywQWKpq677q-HSl0Q.jpeg</url>
            <title>Stories by Christian on Medium</title>
            <link>https://medium.com/@christiannaths?source=rss-47e4506a980d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:41:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@christiannaths/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[From Zero to Redux in 3 Minutes]]></title>
            <link>https://medium.com/@christiannaths/from-zero-to-redux-8db779b6ed01?source=rss-47e4506a980d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8db779b6ed01</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-redux]]></category>
            <dc:creator><![CDATA[Christian]]></dc:creator>
            <pubDate>Tue, 14 Feb 2017 00:28:03 GMT</pubDate>
            <atom:updated>2017-02-15T19:10:54.927Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ufTZlV3JGAlFmtpNOqn2UQ@2x.png" /></figure><h4>A simplified guide to using Redux in a React application.</h4><p>For some reason I have a hard time remembering the basic steps required to set up Redux with React. I find the <a href="http://redux.js.org/docs/basics/UsageWithReact.html">official documentation</a> hard to follow, so I’ve written a simplified guide for the sake of future reference.</p><h3>Prologue: Create a new React app</h3><p><em>If you are adding Redux to an existing React app, skip ahead to Step 1</em></p><p>We’ll start by using <a href="https://github.com/facebookincubator/create-react-app">create-react-app</a> to generate a simple React web application.</p><ul><li>npm install -g create-react-app</li><li>create-react-app my-app &amp;&amp; cd my-app</li><li>npm start</li></ul><p>Now open up your project folder in your text editor and you’re ready to go. Your app will open in your browser at <a href="http://localhost:3000/">http://localhost:3000</a></p><h3>Step 1 of 4 — Dependencies</h3><p>Use Yarn or npm to add two required packages:</p><ul><li>yarn add redux react-redux</li></ul><p>There are many ways you can organize your app, but I’ll use a very simple method that puts all your Redux-related code in one place. Create a new folder in your src/ directory called store/, and in that folder add three files: index.js, actions.js, and reducers.js.</p><p>Here’s a quick bash one-liner that will do this for you:</p><ul><li>mkdir ./src/store &amp;&amp; touch ./src/store/{index,actions,reducers}.js</li></ul><p>Your project structure will now look like this:</p><pre>my-app/src<br>       ├── App.css<br>       ├── App.js<br>       ├── App.test.js<br>       ├── index.css<br>       ├── index.js<br>       ├── logo.svg<br>       └── store<br>           ├── actions.js<br>           ├── index.js<br>           └── reducers.js</pre><h3>Step 2 of 4 — Actions</h3><p>Next, we’re going to define some actions. We’ll use these actions later in our component event handlers to manipulate data in the store. In this somewhat contrived example, I am creating actions to handle toggling the user notification settings in my app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9b1d09399c28099763b0227eb323e0f/href">https://medium.com/media/e9b1d09399c28099763b0227eb323e0f/href</a></iframe><p>Here we’re doing two things. First, defining and exporting a TYPES declaration, which we will use when we handle the action. Second, we’re defining and exporting an actions object, in which we’ve defined a function to pass data along to our reducer.</p><h3>Step 3 of 4 — Reducers</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99006f40e4bdf1e261b2312f0f68e482/href">https://medium.com/media/99006f40e4bdf1e261b2312f0f68e482/href</a></iframe><p>In this file we’ll create and export our reducers. Reducers are used to determine how data in the Redux store is updated.</p><h3>Step 4 of 4 — Store and &lt;Provider&gt;</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fe62355ded7ad834b9608882027efcc/href">https://medium.com/media/1fe62355ded7ad834b9608882027efcc/href</a></iframe><p>Here we import our reducers, combine them into a single “root reducer”, and create our store. The createStore method returns a store object to use with React-Redux’s &lt;Provider&gt; component, in which we’ll wrap our entire application before rendering it to the DOM.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/493927974a48ce0b4c5fc81faf1ef600/href">https://medium.com/media/493927974a48ce0b4c5fc81faf1ef600/href</a></iframe><p>And that’s it for the setup! Next let’s look at using our Redux store by connecting it to components and dispatching actions.</p><h3><strong>Epilogue: Connecting Components</strong></h3><p>Continuing with my contrived example, let’s create a controlled checkbox component. The settings.notifications key in the Redux store will control the state of the component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b286ed42d16f3c7fe0e6e62b3b894282/href">https://medium.com/media/b286ed42d16f3c7fe0e6e62b3b894282/href</a></iframe><p>A couple of noteworthy points:</p><ul><li>onChange will dispatch the setNotifications action we created earlier.</li><li>mapStateToProps, when passed to connect(), maps keys from the Redux store to props in the component.</li></ul><p>Now any connected component will have access to the value that is set by the above component. For example, if we create a component to display the state of the user settings…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ff05756f78ed3b47296aa34b788adf1/href">https://medium.com/media/4ff05756f78ed3b47296aa34b788adf1/href</a></iframe><p>…and use these components somewhere in our app…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0e7f77223a6c8fc8cb07635bdf4709b/href">https://medium.com/media/b0e7f77223a6c8fc8cb07635bdf4709b/href</a></iframe><p>…we’ll get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dxWyX-qUisqc16bVktdOEA.gif" /><figcaption>http://localhost:3000</figcaption></figure><ul><li>You can <a href="https://github.com/christiannaths/simplified-react-redux-boilerplate">download this boilerplate from Github</a></li><li>For more, check out: <a href="http://redux.js.org/">http://redux.js.org/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8db779b6ed01" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>