<?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 davidvlsea on Medium]]></title>
        <description><![CDATA[Stories by davidvlsea on Medium]]></description>
        <link>https://medium.com/@davidvlsea?source=rss-18cfe56950f1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hOZYABmLjrDhOJ-V.jpg</url>
            <title>Stories by davidvlsea on Medium</title>
            <link>https://medium.com/@davidvlsea?source=rss-18cfe56950f1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:03:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@davidvlsea/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[React without undue complications]]></title>
            <link>https://medium.com/@davidvlsea/react-without-undue-complications-f3490403fdc0?source=rss-18cfe56950f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3490403fdc0</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[davidvlsea]]></dc:creator>
            <pubDate>Tue, 10 Nov 2015 22:32:07 GMT</pubDate>
            <atom:updated>2015-11-12T01:29:11.018Z</atom:updated>
            <content:encoded><![CDATA[<p>After working with React these past few months I’ve become quite smitten with it. Building interactive single page applications is an enjoyable and empowering experience. The whole concept of structuring an application around components is extremely natural and results in very readable code. Project directory structure and naming conventions makes it easy to reason about the codebase, even when stepping into an unfamiliar app.</p><p>Yes, the JSX syntax takes some getting used to, but it quickly begins to feel as it should be. There was a time not so long ago when conventional wisdom mandated that HTML markup and JavaScript be treated like oily rags and open flames, mix them and your app might well spontaneously combust. Unobtrusive JavaScript was the name of the game*.</p><p>The React designers tossed out the old fire safety handbook and built a framework predicated on JavaScript and markup be not just co-located in the same file, but completely intertwined. Rather than exploding in a big fiery mess, turns out this works really well. At the heart of most web applications is the logic of what DOM elements to render, under which conditions, and bound to what data. Forcing the markup representation and the driving render logic to live apart makes the code more difficult to reason about and forces lots of developer context switching.</p><p>The beauty of React is the conceptual surface area is really quite small. As long as you stick to the guiding principles of structuring UI elements as reusable components and adhering to unidirectional data-flow, you relatively quickly get the point where you can crank out highly interactive user experiences with ease. And if you’re compiling ES6 with <a href="https://babeljs.io/">babel</a> and bundling with <a href="http://browserify.org/">browserify</a> or <a href="https://webpack.github.io/">webpack</a> (which I suggest you do), just import node modules to accomplish anything that doesn’t belong in the component itself. No need for an all-encompassing framework that mandates you make API calls or model business entities a certain way. React focuses just on presentation which is refreshing.</p><p>The next logical step in the evolution of a newly minted React programmer is to incorporate the <a href="https://github.com/rackt/react-router">react-router</a> to power single page applications. And more awesomeness ensues. The design of the router is quite clever in that Route objects are themselves React components that can be declared with JSX and nested to represent hierarchical URL structures. One of my favorite techniques is to use a parent Route to represent the master layout where the overall page structure including global header, sidebar, etc. are declared. It provides a very succinct and elegant way to keep the URL and the current view in-sync with the support you’d expect for HTML5 history (no unsightly hashes).</p><p>At this point you have the tools required to build a sophisticated single page application that seamlessly updates the right bits of the DOM in response to user actions and other events. However to make it a “real world” application, the JavaScript digerati would have you believe you now need to introduce either <a href="https://facebook.github.io/flux/">Flux</a> or it’s shiny new offshoot <a href="http://redux.js.org/">Redux</a>. It’s at this point the once smooth road to React proficiency begins to get quite bumpy.</p><p>Both build upon the core unidirectional data-flow tenet of React, but come with the cost of a barrage of new concepts, modules, and syntactical trickery: a<em>ctions</em>, s<em>tores</em>, a<em>ction creators</em>, d<em>ispatchers</em>, c<em>ontroller views, reducers, redux-router, </em>something called <em>redux-thunk, </em>and<em> </em>on and on<em>. </em>If your experience is anything like mine, you’ve felt the frustration of cruising along nicely with core React and react-router, then having to hit the brakes, spending hours head-scratching trying to figure out errors like “dispatch is undefined” and wrapping your brain around functions that accept an array of function args and return yet another function.</p><p>Look, there’s nothing wrong with advanced techniques and concepts, and the folks behind Flux and Redux are undoubtedly highly capable. The patterns they introduce, if implemented properly, do provide benefits for the most <em>complex</em> of apps. But I sense a growing impression amongst developers that <em>all </em>React<em> </em>apps, regardless of size, necessitate Flux or Redux. I’d argue this introduces a high barrier to success and will alienate a large swath of front-end developers right at a time when React is well poised to make major gains in adoption.</p><p>I wonder just how much this is genuinely beneficial and how much is pursuit of functional architectural purity. Might there be a simpler way to achieve the same underlying goals while *reducing* the number of moving parts and boilerplate?</p><p>At the risk of oversimplifying, the basic goal of Flux/Redux amounts to centralizing the storage and modification of application state and the mechanism to propagate state changes down throughout the component hierarchy. To accomplish this in a clear and straightforward way, I’ll describe a basic pattern I’ve used on moderately large apps that requires no additional npm dependencies beyond react, react-router, and an EventEmitter implementation of your choosing (I use the one from <a href="https://github.com/bevacqua/contra">contra</a>).</p><p>Generally all React apps have a root component, often called <em>App.jsx</em> or <em>Root.jsx</em>. Since this is a singleton entity let’s just make it the central place where global state is stored and mutated. As long as the root component’s state is passed as props to it’s children, calling <em>setState</em> at this level gives us the desired state propagation for free. The <em>dispatcher</em> is just a lightweight module that exports an EventEmitter and a map of action name constants. Rather than fancy injection of the <em>dispatcher </em>into Component instances, each module simply imports it.</p><p>Imagine you are building a contact management application. To start off, the app consists of a default <em>ContactList</em> component that renders a list of contacts and an <em>AddContact</em> component for entering a new contact. Rather than describe in sentences what’s going on, I’ll just let the code do the talking. I’m not a framework guru, just a developer trying to be as productive as possible building compelling user experiences with React, so feel free to take it, leave it, or adapt as you see fit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4344ab539900102b2c8319b22c3057a0/href">https://medium.com/media/4344ab539900102b2c8319b22c3057a0/href</a></iframe><p>*<em>Yes I know the rationale of ensuring web apps work even if JavaScript is disabled, but frankly those aren’t the types of apps I build (and if were a strict requirement, I’d opt for the approach of showing a message in a &lt;noscript&gt; tag with a link to a low-fi version, a la gmail).</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3490403fdc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>