<?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 Rohan Dang on Medium]]></title>
        <description><![CDATA[Stories by Rohan Dang on Medium]]></description>
        <link>https://medium.com/@rohandang?source=rss-89015e3c2940------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*6rQmXzAp15l20DRHAvioKQ.jpeg</url>
            <title>Stories by Rohan Dang on Medium</title>
            <link>https://medium.com/@rohandang?source=rss-89015e3c2940------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:44:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohandang/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[Using React in a Production App — Implementation Guide]]></title>
            <link>https://medium.com/opendoor-labs/using-react-in-a-production-app-implementation-guide-94ec249dc78b?source=rss-89015e3c2940------2</link>
            <guid isPermaLink="false">https://medium.com/p/94ec249dc78b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Rohan Dang]]></dc:creator>
            <pubDate>Mon, 09 Oct 2017 18:14:13 GMT</pubDate>
            <atom:updated>2020-02-05T16:35:54.401Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using React in a Production App — 2 of 2</h3><h4>Part 2: An implementation guide to use React in a real world setup</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uDopox3syLSrZv9aQpmvcQ.png" /></figure><p><strong><em>In </em></strong><a href="https://medium.com/@rohandang/4cd552d058ad"><strong><em>Part 1</em></strong></a><em>, we talked about how at </em><a href="https://www.opendoor.com/"><em>Opendoor</em></a><em> we made some decisions in the way we’re using React, and how anyone running React in a real world production app might need to make those same decisions, and why. </em><strong><em>In this part</em></strong><em>, we’ll walk through how to actually implement those decisions.</em></p><p>First, let’s recap the React stack that we settled on:</p><ul><li><a href="https://github.com/reactjs/redux"><strong>Redux</strong></a><strong> </strong><em>for state management</em></li><li><a href="https://github.com/facebook/immutable-js/"><strong>ImmutableJS</strong></a><strong> </strong><em>for immutability</em></li><li><a href="https://github.com/reactjs/reselect"><strong>Reselect</strong></a> <em>for accessing memoized derived data from the store</em></li><li><a href="https://github.com/redux-saga/redux-saga"><strong>Redux-Saga</strong></a><strong> </strong><em>for async side-effects</em></li><li><a href="https://github.com/ReactTraining/react-router"><strong>React Router v4</strong></a><strong> </strong><em>for URL routing</em></li><li><a href="https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux"><strong>React Router Redux</strong></a><strong> </strong><em>for binding routes with Redux</em></li><li><a href="https://github.com/facebook/jest"><strong>Jest</strong></a> <em>for snapshot testing and as a test runner</em></li><li><a href="https://github.com/airbnb/enzyme/"><strong>Enzyme</strong></a><strong> </strong><em>for traversing and testing a component’s DOM</em></li><li><a href="https://github.com/nfl/react-helmet"><strong>Helmet</strong></a> <em>for &lt;meta&gt; tags management</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbg93eHGaU_Y4egkCCN4zg.png" /><figcaption>Opendoor’s React Stack</figcaption></figure><p>Now, let’s talk about how you can set up all these pieces for your app.</p><p>We’ll discuss the following areas:</p><ol><li>Setting up the Redux store to <strong>manage your app’s state</strong></li><li>Setting up Redux-Saga to <strong>handle API requests and other side-effects</strong></li><li>Setting up React Router v4 to <strong>manage URL routing</strong></li><li>Finally, <strong>putting it all together</strong></li></ol><h3>1. Manage your app’s state</h3><p>Your app’s state will be held and managed by Redux, using ImmutableJS to create immutable state, and using Reselect to pull data out of it (direct and computed).</p><p>Redux is comprised of <em>Actions</em> and <em>Reducers</em>. Actions are just plain ‘ol JS objects that carry the information necessary to reduce your app state to something new. Typically, an action object has an identifier for the type of action it is, and an optional payload to go along with it. Your app invokes an action by calling a dispatch function with the action object. Redux then calls your reducer with the action object that you use to grab the type and payload out of and return a new resulting state accordingly.</p><blockquote>If you’re interested in learning more about how Redux works, I highly recommend browsing the very readable, <a href="https://medium.com/redux.js.org">official Redux docs</a></blockquote><p>We use ImmutableJS to create immutable state that prevents accidental modifications of the state directly. All changes to the state flow through the action → reducer path.</p><p>Reselect is used to expose parts of your state directly, as well as supplement it with computed properties that look just like a slice of the state to your app. Reselect automatically takes care of memoizing them for you!</p><h4>Installation</h4><p>Let’s start by installing <a href="https://github.com/reactjs/redux">Redux</a>, <a href="https://github.com/facebook/immutable-js/">ImmutableJS</a>, and <a href="https://github.com/reactjs/reselect">Reselect</a> to create a store that you can read and write to.</p><pre>npm install --save redux react-redux<br>npm install --save-dev redux-devtools<br>npm install --save immutable<br>npm install --save reselect</pre><h4>Action Types</h4><p>First off, action objects need unique identifiers to represent their type. To avoid typos and accidental re-use, it’s best to use constants for this. For convenience, put them all in an actionTypes.js file, then you can easily access them from both reducers and sagas:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21c35fca6e704b7915c1d97cedf9e292/href">https://medium.com/media/21c35fca6e704b7915c1d97cedf9e292/href</a></iframe><h4>Action Creators</h4><p>Next, you want to create some action creators, which are basically functions that take in the information you want to capture in your dispatched action, and generate the action object for you.</p><p>To be consistent, we use the FSA (<a href="https://github.com/acdlite/flux-standard-action">Flux Standard Action</a>) format to create action objects, which basically means the bulk of your information will be put inside a payload key in the action object. Here’s an example actions.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f4cb79a9542954ad02fdb8e301bbee3/href">https://medium.com/media/9f4cb79a9542954ad02fdb8e301bbee3/href</a></iframe><h4>Reducer</h4><p>Now, let’s write a reducer that will be responsible for producing a new state based on the actions it receives.</p><blockquote>Reducers are “pure functions” — given a fixed set of inputs, they always return the same state.</blockquote><p>For this reason, you don’t put any network calls in your reducers. That’s where a middleware like saga comes in to process your network calls and emit new actions for the reducer to process.</p><p>The reducer is where you will define what your initial state should be. You’ll notice we’re using some <a href="https://facebook.github.io/immutable-js/docs">Immutable</a> stuff here, that’s because your reducer should be responsible for making sure only Immutable objects are going into your store and should be <a href="http://facebook.github.io/immutable-js/docs/#/fromJS">converting</a> any incoming payload into Immutable objects for the new state.</p><p>ImmutableJS has <a href="https://facebook.github.io/immutable-js/docs/#/List/toJS">pretty good documentation</a> on the various methods you can invoke on Immutable objects to perform almost any operation you’d want. There are <a href="http://untangled.io/immutable-js-all-the-examples-youll-ever-need-to-get-set-and-delete-data-from-lists/">many</a> <a href="http://thomastuts.com/blog/immutable-js-101-maps-lists.html">guides</a> and <a href="http://ricostacruz.com/cheatsheets/immutable-js.html">cheatsheets</a> out there on ImmutableJS, but I usually found myself referencing the <a href="https://facebook.github.io/immutable-js/docs/#/">official docs</a> most often.</p><blockquote>Most important thing to remember with Immutable is when you’re dealing with immutable objects and when you’re not. It’s best to be consistent in your approach — e.g. action payloads are always JS objects, selectors are always immutable objects, etc.</blockquote><p>The performance characteristics of converting back/forth between JS↔Immutable: <a href="https://facebook.github.io/immutable-js/docs/#/fromJS">fromJS</a> (converting JS objects to Immutable) is not too bad, but <a href="https://facebook.github.io/immutable-js/docs/#/List/toJS">toJS</a> (converting an Immutable object back to JS) is an <a href="https://twitter.com/leeb/status/746733697093668864">expensive call</a> that you want to reasonably minimize the use of.</p><p>Now, for writing your reducer code, a common practice is in your reducer.js switch on the action type to catch the right action and return a new immutable state appropriately:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/673b5893e47c4edcba302f595481661e/href">https://medium.com/media/673b5893e47c4edcba302f595481661e/href</a></iframe><h4>Selectors</h4><p>Selectors give access to the state, allowing you to combine parts of your state to create computed properties. For example, you can have a selector that uses an ID or token in your URL (populated into the store by <a href="https://github.com/reactjs/react-router-redux">react-router-redux</a>) to grab a record from another part of your store using that identifier!</p><p>Using Reselect to create your selectors, we get performance benefits through memoization for complex selectors (when the inputs don’t change). Since the state is of type Immutable, we use methods from the Immutable API to run any operations as necessary. <a href="https://facebook.github.io/immutable-js/docs/">This</a> is a good page to bookmark for reference.</p><p>Add a selectors.js file that will hold your static and computed selector functions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a389ad48bfbb974ae41d50883d53cdf/href">https://medium.com/media/9a389ad48bfbb974ae41d50883d53cdf/href</a></iframe><h4>Exporting it all</h4><p>At this point, you should have a directory structure like this:</p><pre>/myApp<br>└─── actions.js<br>└─── actionTypes.js<br>└─── reducer.js<br>└─── selectors.js</pre><p>Let’s add an index.js file here that will export all your Redux items:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb9593ff6549d0c0584b7789bd937e71/href">https://medium.com/media/cb9593ff6549d0c0584b7789bd937e71/href</a></iframe><p>And a parent reducers.js that exports all your reducers for the initializing module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/369fe9b65d94fa258e10cbe6f8088c75/href">https://medium.com/media/369fe9b65d94fa258e10cbe6f8088c75/href</a></iframe><p>We’ll go over more code organization best practices later, but for now it’s a good idea to put all your redux code in its own directory, maybe something like store.</p><p>Your directory structure finally should look something like this:</p><pre>/store<br>   /myApp<br>     └─── actions.js<br>     └─── actionTypes.js<br>     └─── index.js<br>     └─── reducer.js<br>     └─── selectors.js<br>   reducers.js</pre><h4>Connecting your components</h4><p>In order to gain access to the state, you connect your components to the state using the connect method from redux to wrap around your final component class when exporting it.</p><p>The connect function takes two arguments, first one maps parts of the state and makes them available as props within your component, and the second (optional) one maps actions as dispatch functions and makes them available on props as well. You can choose to only implement one or both, depending upon your component’s needs. The result of this call is another function that you pass your component to and export the result.</p><p>Here’s what a sample connected component might look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c3205de0a5a77d321f635eb0db4feb2/href">https://medium.com/media/9c3205de0a5a77d321f635eb0db4feb2/href</a></iframe><h3>2. Handling API requests and other side-effects</h3><p>In this section we’ll talk about setting up <a href="https://redux-saga.js.org/">Redux-Saga</a> to achieve asynchronous side-effects as a result of dispatching your actions.</p><h4>Installing</h4><pre>npm install --save react-saga</pre><h4>Using for API calls</h4><p>One of the typical use cases for this is to handle your API calls for posting and fetching data from your backend.</p><p>Sagas are invoked after Redux is done taking the action through the reducers. They can also dispatch other actions to change your application state as a result of a network call for example.</p><p>So you can imagine having a series of action and effects like this:</p><ol><li>Dispatch fetchConfig() action<br><strong>Reducer</strong> → Sets state.loading = true<br><strong>Saga</strong> → Makes an API call to fetch configuration from server</li><li>On API call return, the saga dispatches receiveConfig(config)<br><strong>Reducer</strong> → Sets state.config = config; loading = false</li></ol><p>Here’s a sample code for something like that:</p><p>In your <strong>actions.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d3ee26d298e13452566e7dec5393e68/href">https://medium.com/media/7d3ee26d298e13452566e7dec5393e68/href</a></iframe><p>In your <strong>actionTypes.js</strong></p><pre>export const FETCH_CONFIG = &#39;@@co/store/product/fetchConfig&#39;;<br>export const RECEIVE_CONFIG = &#39;@@co/store/product/receiveConfig&#39;;</pre><p>In your <strong>reducers.js</strong></p><pre>import { fromJS } from &#39;immutable&#39;;<br>import * as actionTypes from &#39;./actionTypes&#39;;</pre><p>Finally, in your <strong>saga.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d93dfc6c30263abc87d899d9897ec7cf/href">https://medium.com/media/d93dfc6c30263abc87d899d9897ec7cf/href</a></iframe><p>There are two ways to resolve <a href="https://redux-saga.js.org/docs/advanced/Concurrency.html">concurrency issues</a> when listening for actions: takeLatest <em>(ignore concurrent calls and take the latest) </em>and takeEvery <em>(each concurrent call triggers the saga)</em>. As you can imagine, both are suitable for their own unique situations.</p><p>Note, another good use case for sagas is to <strong>use it for logging analytics</strong>. Your components can simply call a trackEvent type of an action that you can have an analytics saga listen for and standardize all your tracking in one place!</p><h3>3. Managing URL routing</h3><p><a href="https://github.com/ReactTraining/react-router">React Router</a> + <a href="https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux">React Router Redux</a> — URL Routing</p><h4>Installation</h4><p>Let’s start by installing the libraries</p><pre>npm install --save react-router-dom<br>npm install --save react-router-redux@next<br>npm install --save history</pre><p>Note the react-router-redux@next above, in order access your location details through Redux, you need react-router-redux, but to make it work with the latest version of React Router (i.e. v4), you need to install the @next version. This is until a stable version is released.</p><h4>Accessing from the store</h4><p>React-router-redux makes the current location information available in the redux store under the location path, so you can interact with it like any other part of the redux store.</p><p>The shape of the location piece in the store looks like this:</p><pre><strong>location:<br>    pathname</strong>: &quot;/current/url/path&quot;<br>    <strong>search</strong>: &quot;(query params)&quot;<br>    <strong>hash</strong>: &quot;(hash target)&quot;<br>    <strong>key</strong>: &quot;abcd1234&quot;</pre><p>You can also modify it through these store actions that you can dispatch:<br>push(location), replace(location), go(number), goBack(), goForward() — like any other actions, these can be mapped directly from your components, or more appropriately, accessed via your <em>sagas</em>.</p><p>You can read more about it over <a href="https://github.com/reactjs/react-router-redux">here</a>.</p><h4>Setting up the routes</h4><p>In the root of your react app, create a routes directory with index.jsx file holding your routes information, something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dffd209bb279352c51b80be9aa3ef30/href">https://medium.com/media/9dffd209bb279352c51b80be9aa3ef30/href</a></iframe><p>Note: Use :name to pass portions of the URL down to the component as props.</p><p>A common scenario is to have a base Layout component wrapping most of your pages. One place you might think of doing that might be in the routes itself, by simply wrapping your &lt;Route&gt; elements with a &lt;Layout&gt; component.</p><blockquote>An important gotcha is that any intermediate elements between your <em>&lt;ConnectedRouter&gt;</em> and <em>&lt;Route&gt;</em> would need to either be wrapped with <em>withRouter</em> or pass all the props down so that location changes can propagate and force children to re-render. Otherwise, you can get into some nasty bugs with your URLs changing but content not updating accordingly!</blockquote><h3>4. Putting it all together</h3><p>In your base template, make sure there’s a mounting point for your React app:</p><pre>// app.html</pre><pre>&lt;div id=&#39;root&#39; /&gt;</pre><p>Install Helmet if you’re interested in managing title/meta tags from within your React app:</p><pre>npm install --save react-helmet</pre><p>And finally set up your module.jsx file to look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8897d1dcee0a8e6f73d24f0f8ea2aad9/href">https://medium.com/media/8897d1dcee0a8e6f73d24f0f8ea2aad9/href</a></iframe><h4>Code Organization</h4><p>As a bonus, here’s how we’ve organized our code given all these different pieces.</p><p>There are two main ways to think about organizing your React code — by domain (i.e. entity types, like ‘Button’, ‘PhotoUpload’, etc.) or by nature (i.e. types of files, like components, routes, etc.).</p><p>The approach that worked best for us was to put all our redux code (actions, reducers, selectors) under a store folder, with each redux “app” as a sub-folder, and organize components into two categories:</p><ul><li>Presentational components that go under a components folder — these components are only concerned with display logic, with data and callback handlers passed down as props</li><li>Connected “container” components that go under a containers folder — these components are the ones that are connected to redux, do the data fetching and handling, and are responsible for composing and returning presentational components</li></ul><p>(This approach is inspired by Dan Abramov’s <a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">article</a> about the same.)</p><p>Here’s what such a structure would look like:</p><pre><strong>/react-app</strong></pre><pre>└──<strong>/components</strong><br><strong>   </strong>└──<strong>/__tests__</strong><br>      └──FooComponent.test.jsx<br>   └──FooComponent.jsx<br>   └──FooComponent.css</pre><pre>└──<strong>/containers</strong><br><strong>   </strong>└──<strong>/__tests__</strong><br>      └──FooPage.test.jsx<br>   └──FooPage.jsx<br>   └──FooPage.css </pre><pre>└──<strong>/hocs</strong><br>   └──xyzWrapper.jsx</pre><pre>└──<strong>/routes</strong><br>   └──index.jsx</pre><pre>└──<strong>/store</strong><br><strong>   </strong>└──<strong>/myApp<br></strong>      └──actions.js<br>      └──actionTypes.js<br>      └──index.js<br>      └──reducer.js<br>      └──selectors.js<br>   └──reducers.js</pre><pre>└──<strong>module.jsx</strong></pre><h3>A note about testing</h3><p>We didn’t cover how we’re using <a href="https://facebook.github.io/jest/">Jest</a> and <a href="http://airbnb.io/enzyme/">Enzyme</a> for our tests, but I’ll leave that for another post. In general, both of those together make writing tests and testing React components a breeze, and I highly recommend it!</p><h3>What’s next?</h3><p>We’re in the process of moving to <a href="https://www.typescriptlang.org/"><strong>TypeScript</strong></a> to add type checking. Be sure we’ll share some of our thoughts on the migration and how well it works out for us.</p><p>Also on our list of things to investigate/incorporate: <a href="http://facebook.github.io/immutable-js/docs/#/Record"><strong>Record</strong></a> Immutable types for clearer representation of our data types.</p><p>We’re working hard on open-sourcing some of the tools and patterns that have been working out really well for us. <a href="https://medium.com/opendoor-labs">Subscribe</a> to our blog and look out for any announcements about that in the future!</p><p><em>Opendoor is looking for engineers of all backgrounds to build products and technologies that empower everyone with the freedom to move.</em></p><p><em>Find out more about our jobs on </em><a href="https://stackshare.io/opendoor#jobs"><strong><em>StackShare</em></strong></a><em> or on our </em><a href="https://www.opendoor.com/jobs"><strong><em>careers site</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94ec249dc78b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendoor-labs/using-react-in-a-production-app-implementation-guide-94ec249dc78b">Using React in a Production App — Implementation Guide</a> was originally published in <a href="https://medium.com/opendoor-labs">Open House</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 things I learned at Nordic.js 2017]]></title>
            <link>https://medium.com/opendoor-labs/10-things-i-learned-at-nordic-js-2017-ae111780ba78?source=rss-89015e3c2940------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae111780ba78</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[conference]]></category>
            <dc:creator><![CDATA[Rohan Dang]]></dc:creator>
            <pubDate>Mon, 18 Sep 2017 15:49:38 GMT</pubDate>
            <atom:updated>2020-02-05T16:49:41.805Z</atom:updated>
            <content:encoded><![CDATA[<h4>#7 will shock you!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCh8eeIO9a9TIV9vIpAPOQ.png" /></figure><blockquote>“Hey, I have a ticket to Nordic.js in Stockholm next week, wanna pop over?”</blockquote><p>… asked <a href="https://twitter.com/henrictrotzig">my friend</a> last week. My immediate response?</p><blockquote>“Hell yes!”</blockquote><p>Next thing I know, I was on a plane to Stockholm. ✈️</p><p>I’d never been to <a href="http://nordicjs.com/">Nordic.js</a> (or Sweden) and had no idea what to expect. All I knew was it was a conference about JS, and it was in Stockholm where I would get to see <a href="https://github.com/trotzig">my friend</a>.</p><p>Little did I know that it’d turn out to be one of the best experiences I’ve had at a conference in a long time! So, I’d like to share some of my learnings.</p><blockquote>If you’re interested in Javascripty things and like learning about what’s current and happening in the JS community, here’s what I found to be cool and eye-opening.</blockquote><p>Quickly, a little bit about me — I’m an engineer at <a href="https://www.opendoor.com/">Opendoor</a> in San Francisco. Opendoor is revolutionizing the way people think about buying and selling homes, making it incredibly simple and easy through technology. I never took JS seriously until recently when I got <a href="https://medium.com/opendoor-labs/using-react-in-a-production-app-4cd552d058ad">involved</a> with it and started to see how sophisticated and amazing it really is. I have been loving every bit of it since then. Attending this conference was an opportunity for me to get to meet the community, expand my vocabulary and get a feel for how to think in JS.</p><p>Here are the highlights of what I learned, in no particular order.</p><h3>1. State of JS in 2017 — React, Redux, TypeScript FTW</h3><p><a href="http://stateofjs.com/">State of Javascript</a> — by <a href="https://twitter.com/SachaGreif">Sacha Greif</a></p><blockquote><strong>My TL;DR highlight</strong>:<strong> </strong>React, Redux, TypeScript, ES6 are the clear winners of where the community seems to be headed!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xB_6WwrQiZYS3IAut6CZfg.png" /><figcaption>The State of JS in 2017</figcaption></figure><p>Sacha gave us a sneak peek at the 2017 results from the <a href="https://stateofjs.com/">survey</a> taken by over 20K developers. In addition to the very useful insights, I loved the selected comments he shared towards the end —</p><blockquote>“The state of JavaScript is there is too little attention to keeping things simple.”</blockquote><p>And this little gem —</p><blockquote>“Every time I write something in JavaScript I’m surprised that it works.”</blockquote><h3>2. Don’t use Aria (use native controls)</h3><p><a href="http://decks.tink.uk/2017/nordicjs/index.html#22">You’re only supposed to blow the bloody doors off!</a> — by <a href="https://twitter.com/leoniewatson">Léonie Watson</a>, W3C Advisory Board</p><blockquote><strong>My TL;DR highlight</strong>: Aria is an escape hatch — you shouldn’t need it in the first place — use as much of native controls as possible!</blockquote><p>If you use custom controls and start adding Aria tags, you’ll inevitably miss something and break the screen readers. Seeing a live demo of how painful it can get when it doesn’t work was really enlightening. It really shouldn’t take that much more effort to make a native &lt;button&gt; work for your use case, instead of using something like &lt;a href=&quot;#&quot; role=&quot;button&quot;&gt;.</p><h3>3. Write async code in a sync manner</h3><p><a href="http://slides.com/ducin/5-architectures-of-asynchronous-javascript#/">5 architectures of asynchronous JavaScript</a> —by <a href="https://twitter.com/tomasz_ducin">Tomasz Ducin</a></p><blockquote><strong>My TL;DR highlight</strong>: Promises + Generators = Async Await</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TlSGqQelij9PQSiaYibolg.png" /></figure><p>I loved how Tomasz gradually walked us through the evolution of async await and really got into the details of how it all works. Highly recommend going through his <a href="http://slides.com/ducin/5-architectures-of-asynchronous-javascript#/">deck</a> if you’re interested in deeply learning the async programming concepts in JS.</p><p>His summary towards the end captured it best —</p><ul><li><em>For a single async operation, a </em><strong><em>promise</em></strong><em> is enough.</em></li><li><em>For a combination of different operations — use </em><strong><em>async await</em></strong><em>.</em></li><li><em>But if something is repetitive — make it an </em><strong><em>observable stream</em></strong><em>.</em></li></ul><h3>4. Build reusable react components</h3><p><a href="https://speakerdeck.com/marsjosephine/nordicjs-best-practices-for-reusable-ui-components">Best Practices for reusable UI components</a> — by <a href="https://twitter.com/marsjosephine">Mars Jullian</a>, Netflix</p><blockquote><strong>My TL;DR highlight</strong>: Make sure to not leave any “<a href="https://speakerdeck.com/marsjosephine/nordicjs-best-practices-for-reusable-ui-components?slide=34">backdoors</a>” in your UI components!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kGImi_Ih3WuElm_rAMeQBA.png" /></figure><p>There’s a skill to building your react UI components in a reusable manner, and Mars really highlighted the difference. They core message was that reusable components need to be <strong><em>self-sufficient</em></strong> and <strong><em>easy to integrate with</em></strong>.</p><h3>5. CSS Grid is a thing!</h3><p><a href="https://www.slideshare.net/rachelandrew/solving-layout-problems-with-css-grid-friends-nordicjs">Solving layout problems with CSS Grid and friends</a> — by <a href="https://twitter.com/rachelandrew">Rachel Andrew</a>, CSS Working Group Expert</p><blockquote><strong>My TL;DR highlight</strong>: Start using display: grid. It’s awesome and works (if you can ditch IE10).</blockquote><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout">CSS Grid Layout</a> is a useful tool for 2D layouts (when you want to control both rows AND columns), and really <a href="https://rachelandrew.co.uk/archives/2016/03/30/should-i-use-grid-or-flexbox/">complements</a> the use of Flexbox.</p><p>Biggest difference is in a grid layout, you’re defining the grid first and placing items inside it, versus in flexbox, your layout is defined mostly by the items inside it.</p><p>Another interesting highlight was learning about the new fr unit (fr stands for <strong><em>fractional</em></strong>), which essentially replaces the % unit for width and height properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*LGBWAf09k4Aw7DFaZPKYdQ.png" /><figcaption>Asking too much here</figcaption></figure><p>CSS Grid is <a href="http://caniuse.com/#feat=css-grid">available in most</a> modern browsers, with only partial support in IE.</p><p>Here’s the best place to learn all about it: <a href="https://gridbyexample.com/">gridbyexample.com</a>.</p><p>More resources on her Nordic.js page over <a href="https://rachelandrew.co.uk/speaking/event/nordicjs?utm_content=buffer4274e&amp;utm_medium=social&amp;utm_source=twitter.com&amp;utm_campaign=buffer">here</a>.</p><h3>6. Anyone can contribute to ECMAScript</h3><p><a href="https://kni.sh/nordicjs-2017">The hilarious misadventures of being a platform downstream from your language</a> — by <a href="https://twitter.com/mylesborins">Myles Borins</a>, Google</p><blockquote><strong>My TL;DR highlight</strong>: <a href="https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md">Contributing</a> to the future of the JS language can start with a simple pull request to the ecma262 repo!</blockquote><p>TC39 is a committee that implements the ECMA-262 specification which eventually JS is an implementation of. If you’re unhappy about something or have ideas on how to improve the language (!), you can have your voice heard too (start by <a href="https://v8.github.io/test262/website/default.html">testing</a> it).</p><p>It was really cool to walk through the process of how changes in the ECMAScript specification comes to be and how transparent it all really is!</p><h3>7. [!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[]</h3><p>Down the Rabbit Hole: JS in Wonderland — by <a href="https://twitter.com/koste4">Claudia Hernández</a></p><blockquote><strong>My TL;DR highlight</strong>: These six letters are enough to do anything in JS: !()+[]</blockquote><h3>Клава ᕕ( ᐛ )ᕗ on Twitter</h3><p>There you go! Q: What is a minion&#39;s favorite JavaScript expression? A: baNaNa https://t.co/LfYMAytPgn</p><p>I’d heard the baNaNa joke above, but what was new was actually learning about a whole <a href="http://www.jsfuck.com/">vocabulary</a> that can be created by exploiting all the quirks of JS (like the truthiness of []), then putting it together to pretty much do anything (like write the entire <a href="https://github.com/fasttime/jquery-screwed">jQuery library</a> 😱).</p><p>On a more practical note, Claudia showed how this way of programming led to the discovery of a serious hack when eBay’s security checks to prevent inclusion of scripts or iFrames were bypassed by the <a href="http://www.jsfuck.com/">JSF*ck</a> style of programming!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lt0Nnm_I2zgsxA_waRhubw.png" /></figure><p>I also liked this parting quote from her talk —</p><blockquote>That’s the point about the science. We should keep on discovering by pushing the limits even though there is no practical use in short run.</blockquote><h3>8. Performance matters</h3><p><a href="https://speakerdeck.com/benschwarz/beyond-the-bubble-1">Beyond the bubble</a> — by <a href="https://twitter.com/benschwarz">Ben Schwarz</a>, Calibre</p><blockquote><strong>My TL;DR highlight</strong>: The Web in 2017: Making people wait for text to render. <em>🙈<br></em>Some very interesting, easy to follow checklists for quick perf wins (learned that font-display: swap is a thing!)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNHhkJ6ffBH0O-Vy7Zxe3Q.png" /><figcaption>Putting performance into perspective</figcaption></figure><p>Ben definitely put the cost of performance into perspective then gave some pretty good, easy to follow hints on how to avoid common pitfalls and improve performance of your web apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvqlWWXHFI_g1Pr17w-_Yw.png" /></figure><p><strong><em>Multiple highlights:</em></strong></p><ul><li><a href="https://speakerdeck.com/benschwarz/beyond-the-bubble-1?slide=21">Moto G4</a> is the best phone to capture the “average” mobile device in 2017</li><li><a href="https://developers.google.com/web/updates/2017/07/devtools-release-notes#throttling">Throttle CPU in Chrome dev tools</a> to see how your site performs</li><li>Lie-fi 🙃 — the wifi that your device says you have but you know you don’t</li><li>Custom fonts have perf gotchas, keep these things in mind:<br> → Fonts are not requested until there is text to render<br> → Should use <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content">preload</a> to load critical resources (like fonts) early<br> → Use font-display: swap to use a system font while a custom one loads<br> → Prefer <em>woff2</em> and <em>woff</em> formats wherever possible (better compression)</li><li>Code splitting is good 👍</li></ul><h3>9. Use RxJS to make interactive animations!</h3><p>Reactive Web Animations with <a href="http://reactivex.io/rxjs/">RxJS</a> — by <a href="https://twitter.com/davidkpiano">David Khourshid</a>, Microsoft</p><blockquote><strong>My TL;DR highlight</strong>: Just check out this interaction built using RxJS</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fdavidkpiano%2Fembed%2Fpreview%2FxLKBpM%3Fheight%3D600%26slug-hash%3DxLKBpM%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fdavidkpiano%2Ffull%2FxLKBpM%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fcodepen-thumbnails%2FPen%2F16633974%2Fthumbnail.small.jpg%3Fv%3D1500785600&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/818cf1ac240e648a3cefc686d093d39b/href">https://medium.com/media/818cf1ac240e648a3cefc686d093d39b/href</a></iframe><p>When you think about animations as a function of state and time, you start to get the power of combining something like RxJS into a visual animation and UI feedback tool.</p><p>I found it really interesting and fresh to think about animations this way. <a href="https://rxviz.com/">RxViz.com</a> has some beautiful ways to visualize this concept even further.</p><h3>10. Next.js is my new favorite thing</h3><p>TBA.js — by <a href="https://twitter.com/rauchg">Guillermo Rauch</a>, ZEIT</p><blockquote><strong>My TL;DR highlight</strong>: <a href="https://github.com/zeit/next.js/">Next.js</a> is a lightweight framework to quickly build server-rendered React apps, code-split by routes that mimic simple file structure. Definitely worth trying it for the next thing I build!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*Ms_v499lvFW6L3q66do0eQ.png" /></figure><p>Guillermo introduced me to the amazing world of <a href="https://github.com/zeit/next.js/">Next.js</a>. In my own words, it looks like a wrapper framework that makes it incredibly easy to build and deploy React apps with all the sensible configurations figured out for you by default.</p><p>Another interesting way I read it being described as is it’s just like PHP (file based routing, server rendered by default, etc.), but using JS and React.</p><p>Let me just list their amazing set of features from the <a href="https://learnnextjs.com/basics/getting-started">official docs</a>:</p><ul><li>Server-rendered by default</li><li>Automatic code splitting for faster page loads</li><li>Simple client-side routing (page based)</li><li>Webpack-based dev environment which supports <a href="https://webpack.js.org/concepts/hot-module-replacement/">Hot Module Replacement</a>(HMR)</li><li>Able to implement with Express or any other Node.js HTTP server</li><li>Customizable with your own Babel and Webpack configurations</li></ul><p>The demo simply blew me away. With almost no configuration, we were able to get a React app with all these features listed above, up and running in no time.</p><p>Very impressed, can’t wait to try it out for my next project!</p><p><strong>Bonus</strong>: He also talked about another pretty awesome tool called <a href="https://zeit.co/now">Now.js</a> (also from Zeit folks). With a single line command it takes your code and deploys it to a publicly accessible Node.js app within seconds. Works with static, node (package.json) or dockerfile deployments.</p><h3>Many thanks!</h3><p>That was just a glimpse into the Nordic.js 2017 conference. I called out the things that stood out to <em>me</em>, but there were incredible other talks given by some really talented folks. Be sure to <a href="http://nordicjs.com/speakers">check them all out</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/0*KN-uQmXZLwQq4xS1." /></figure><p>Also, goes without saying but what an excellent job by the conference organizers —</p><p><a href="https://twitter.com/javve">Jonny Strömberg</a>, <br><a href="https://twitter.com/martinaelm">Martina Elm</a>, and <br><a href="https://twitter.com/jede">Johannes Edelstam</a>!</p><p>👏</p><p>Thanks for welcoming me in this community and showing me a good time!</p><p>Until next year!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*QFAGr6JPJHjoKGfQxg5o4w.png" /></figure><p><em>Opendoor is looking for engineers of all backgrounds to build products and technologies that empower everyone with the freedom to move.</em></p><p><em>Find out more about our jobs on </em><a href="https://stackshare.io/opendoor#jobs"><strong><em>StackShare</em></strong></a><em> or on our </em><a href="https://www.opendoor.com/jobs"><strong><em>careers site</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae111780ba78" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendoor-labs/10-things-i-learned-at-nordic-js-2017-ae111780ba78">10 things I learned at Nordic.js 2017</a> was originally published in <a href="https://medium.com/opendoor-labs">Open House</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using React in a Production App]]></title>
            <link>https://medium.com/opendoor-labs/using-react-in-a-production-app-4cd552d058ad?source=rss-89015e3c2940------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cd552d058ad</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rohan Dang]]></dc:creator>
            <pubDate>Mon, 21 Aug 2017 18:23:56 GMT</pubDate>
            <atom:updated>2020-02-05T16:35:12.383Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Using React in a Production App</strong> — 1 of 2</h3><h4>Part 1: Decisions you’ll need to make to use React in the real world</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xrtBSqzL8XWh7WNUNJMRw.png" /></figure><blockquote>This article will share how we at <a href="https://www.opendoor.com/">Opendoor</a> used React in a real world production app, the decisions we made, and why.</blockquote><p>You’ve probably heard of React and have been told <a href="https://twitter.com/wesbos/status/598144948559605760">how awesome it is</a> and that you should be using it. You can find many “<a href="https://github.com/kriasoft/react-starter-kit">React</a> <a href="https://github.com/dabbott/react-express">Starter</a> <a href="http://andrewhfarmer.com/starter-project/">Kits</a>” out there that get you up and running with a basic app in React. But when you try to use it for anything production-ish, you quickly realize that to do something useful, there’s a slew of tools and packages that you’ll need.</p><p>React is different from most JS frameworks, in that it is really a <a href="https://facebook.github.io/react/">library</a>, not a framework, and as such doesn’t impose any opinions about how to use it. While this gives us a lot of freedom, it can also very quickly lead to <a href="https://en.wikipedia.org/wiki/Decision_fatigue">decision fatigue</a> as you try to expand its capabilities with third-party packages.</p><p>We’ll go over our process, decisions, and alternatives considered in landing on the packages stack that helped us build a performant, testable and scalable production app using React.</p><h4>Background on our project</h4><p>Opendoor is on a mission to empower everyone with the freedom to move by making the process of buying and selling homes extremely easy. Often we buy the homes directly from our customers, eliminating the hassles of showings and months of uncertainty.</p><p>We wanted to adopt React given its many benefits (performance, component-first approach, industry adoption). One of React’s strengths is that it can be adopted incrementally into an existing codebase. We decided to start our migration to React with the Input Flow, which is a set of questions that a customer must complete about their home for Opendoor to accurately value it and make an offer.</p><p>With Opendoor’s continued expansion to more cities, the Input Flow became increasingly complex with forked flows and unique questions per city. For example, basement details are an important piece of information about homes in Atlanta but not so much in Phoenix or Las Vegas.</p><p>To continue scaling Opendoor, we needed to substantially change how our Input Flow worked, so it was a good opportunity to take this isolated chunk and rewrite it in React.</p><h4>Our goals</h4><p>We wanted to ship this refactor quickly while laying in the foundations of a React app to easily expand its use in the codebase over time.</p><p>The high-level goals we wanted to accomplish were:</p><ol><li>Write <strong>reusable</strong> and <strong>testable</strong> components that could be composed into different configurations easily.</li><li>Be <strong>performant</strong>. Reduce load times navigating in-between the flow and make the overall app snappy, using local state in a sane manner as the app grows.</li><li><strong>Scale</strong> well with complexity. Have a clean architecture for components to talk to the server and perform other consistent operations like recording analytics.</li></ol><p><em>Note that for now, we were not trying to solve auth in our React app so I’ll skip over it, but that might be an important piece for you.</em></p><h3>The chosen stack</h3><p>In deciding which packages to add on top of React to achieve our goals, we had to not only consider which capabilities we need in our app, but for each of them, which specific package to go with.</p><p>For each decision, there were many alternatives available with competing philosophies and compelling arguments (see my earlier point about “decision fatigue”).</p><p>Our rubric was relatively straightforward: make sure the packages work well with each other, have an active community (that we could participate in as well), and are well-maintained and supported.</p><blockquote>Note that this is what worked for us given our situation and requirements, but YMMV!</blockquote><p>Finally, here’s the React stack that we settled on:</p><ul><li><a href="https://github.com/reactjs/redux"><strong>Redux</strong></a><em> for state management</em></li><li><a href="https://github.com/facebook/immutable-js/"><strong>ImmutableJS</strong></a> <em>for immutability</em></li><li><a href="https://github.com/reactjs/reselect"><strong>Reselect</strong></a> <em>for accessing memoized derived data from the store</em></li><li><a href="https://github.com/redux-saga/redux-saga"><strong>Redux-Saga</strong></a> <em>for async side-effects</em></li><li><a href="https://github.com/ReactTraining/react-router"><strong>React Router v4</strong></a> <em>for URL routing</em></li><li><a href="https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux"><strong>React Router Redux</strong></a> <em>for binding routes with Redux</em></li><li><a href="https://github.com/facebook/jest"><strong>Jest</strong></a> <em>for snapshot testing and as a test runner</em></li><li><a href="https://github.com/airbnb/enzyme/"><strong>Enzyme</strong></a> <em>for traversing and testing a component’s DOM</em></li><li><a href="https://github.com/nfl/react-helmet"><strong>Helmet</strong></a> <em>for &lt;meta&gt; tags management</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbg93eHGaU_Y4egkCCN4zg.png" /><figcaption>Opendoor’s React Stack</figcaption></figure><p>With that, let’s get into the details about each decision.</p><h3>Why we decided on the above</h3><h4><a href="https://github.com/reactjs/redux">Redux</a> — State Management</h4><p>Redux is a simple, but opinionated state management library most commonly used with React. It greatly simplifies how you think about state in your app.</p><blockquote>Redux maintains a single store for the entire state of your app, and it is read-only. Any changes to the state are dispatched through “action” objects that carry the necessary information needed to change the state. The dispatched actions run through a reducer whose job is to use the information in the action to return a new state for your app.</blockquote><p>This unidirectional flow of state changes has couple benefits:</p><ul><li>Makes state changes extremely clear and explicit — no direct manipulation of the state, everything happens through action objects enforcing a clear protocol</li><li>Allows for “<a href="https://www.youtube.com/watch?v=xsSnOQynTHs">time travel debugging</a>” as you step back and forth between each variation of the state since dispatched actions can be simply replayed</li></ul><p><strong><em>Goal wins: </em></strong><em>Helps build a scalable architecture, bringing sanity to state management, as well as making the app more testable and easier to debug!</em></p><p><strong><em>Alternatives:</em></strong><em> </em><a href="https://github.com/mobxjs/mobx"><em>MobX</em></a><em>, </em><a href="https://github.com/facebook/relay"><em>Relay</em></a><em>, </em><a href="https://facebook.github.io/react/docs/state-and-lifecycle.html"><em>this.setState</em></a><em> (i.e. React’s built-in state)</em></p><p><strong><em>Why </em></strong><a href="https://github.com/reactjs/redux"><strong><em>Redux</em></strong></a><strong><em>:</em></strong><em> Strong community support and popularity over competing packages. Way more scalable architecture than managing state using the built-in React APIs.</em></p><h4><a href="https://github.com/facebook/immutable-js/">ImmutableJS</a> — Immutable State Objects</h4><p>ImmutableJS (mostly just called ‘Immutable’) is a collection of immutable data structures with a comprehensive set of available operations.</p><p>Using immutable type for your state ensures you never accidentally modify your state directly, as well as allows for efficient change detection and memoization wins.</p><p><strong><em>Goal wins:</em></strong><em> Makes the app </em><a href="https://facebook.github.io/react/docs/optimizing-performance.html#using-immutable-data-structures"><em>more performant</em></a><em> through reference equality checks instead of value equality checks for detecting when to re-render!</em></p><p><strong><em>Alternatives:</em></strong><em> </em><a href="https://github.com/rtfeldman/seamless-immutable"><em>seamless-immutable</em></a><em>, sheer willpower (no immutable type, being careful to not mutate data directly)</em></p><p><strong><em>Why </em></strong><a href="https://github.com/facebook/immutable-js/"><strong><em>ImmutableJS</em></strong></a><strong><em>: </em></strong><em>Pretty good built-in support for common operations (think: built-in lodash), and strong evidence of successful use with React.</em></p><h4><a href="https://github.com/reactjs/reselect">Reselect</a> — Memoized derived data from the store</h4><p>While you can access store data directly from your components, most likely in a real-world app, you’ll have some derived data that you compute from your state and want consistent access to in your components. Additionally, depending upon the complexity, you’d want it to be memoized for performance reasons.</p><p>This is where Reselect comes in. It acts like an access layer around your Redux store giving you memoized access to direct and derived data from the store. It’s really useful, and you most likely <a href="https://github.com/reactjs/reselect">want it</a>.</p><p><strong><em>Goal wins:</em></strong><em> Big performance boost through memoization, especially when getting into complex selectors that can get expensive to re-compute!</em></p><h4><a href="https://github.com/redux-saga/redux-saga">Redux-Saga</a> — Async Side-Effects</h4><p>Sagas are basically middleware for your Redux app that can listen for certain dispatched actions and trigger any ancillary operations you want as a result of those actions being fired.</p><p>Some examples of when to use sagas:</p><ul><li>Handling API requests to the server</li><li>Recording analytics events</li><li>Firing notifications on certain triggers</li></ul><p><strong><em>Goal wins:</em></strong><em> Helps in scaling architectural complexity as the interface components gets separated from any business logic, allowing the components to only worry about dispatching actions to indicate what happened and side-effects take care of updating state and performing other actions as necessary.</em></p><p><strong><em>Alternatives:</em></strong><em> </em><a href="https://github.com/gaearon/redux-thunk"><em>Redux-Thunk</em></a><em>, </em><a href="https://github.com/redux-observable/redux-observable"><em>Redux-Observable</em></a><em>, </em><a href="https://github.com/redux-loop/redux-loop"><em>redux-loop</em></a></p><p><strong><em>Why </em></strong><a href="https://github.com/redux-saga/redux-saga"><strong><em>Redux-Saga</em></strong></a><strong><em>:</em></strong><em> Easier to test, consolidated place for your app’s side-effects. Also seems to be the most popular and well supported choice from a community point of view.</em></p><h4><a href="https://github.com/ReactTraining/react-router">React Router v4</a> + <a href="https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux">React Router Redux</a> — URL Routing</h4><p>React Router is the de-facto choice when it comes to handling URL routing in your React app. The real question was whether to go with the older v2/v3 API or the complete re-write that is v4.</p><blockquote>Pretty much the entire design and philosophy of React Router <a href="https://reacttraining.com/react-router/core/guides/philosophy/backstory">changed</a> with v4, making it practically a different library from before.</blockquote><p>React Router v4 offers some advanced techniques with routing, allowing you to make routing decisions nested deep within your app, even <a href="https://reacttraining.com/react-router/core/guides/philosophy/dynamic-routing"><em>as the app is rendering</em></a>. We’re not doing any of that for our purposes yet, but it’s something worth evaluating for your app as it can be a powerful tool.</p><p>React Router Redux is an add-on package (now folded into React Router repo), that binds the location information with your Redux store, allowing for your selectors for example to easily access the location information. This is useful if you have some information in the URL (e.g. /&lt;entity-id&gt;/foo) necessary for your app that you would like direct access to in your store.</p><p><strong><em>Alternatives: </em></strong><a href="https://github.com/ReactTraining/react-router/tree/v3/docs"><em>React Router v3</em></a><em>, </em><a href="https://github.com/FormidableLabs/redux-little-router"><em>redux-little-router</em></a></p><p><strong><em>Why </em></strong><a href="https://github.com/ReactTraining/react-router"><strong><em>React Router v4</em></strong></a><strong><em> and </em></strong><a href="https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux"><strong><em>react-router-redux</em></strong></a><strong><em>:</em></strong><em> It’s the latest and greatest, since we were starting a new project from scratch, we wanted to adopt it now and not worry about the deprecation that’s bound to happen.</em></p><p><em>Deciding over redux-little-router was harder and in full honesty, there’s still a chance we’d evaluate switching to over, as there are some quirks and odd behaviors in react-router-redux that can be very frustrating to debug if you’re not fully aware of the intricate details of their working. We’ll go over some of the gotchas in more detail in part 2 of this post.</em></p><h4><a href="https://github.com/facebook/jest">Jest</a> + <a href="https://github.com/airbnb/enzyme/">Enzyme</a> — Testing Solution</h4><p>Jest is a universal testing platform that works especially well as a test-runner for React with a pretty good built-in support for things like snapshot testing. When combined with Enzyme, you get access to a convenient way of traversing, manipulating and asserting the output of your React components.</p><p><strong><em>Goal wins:</em></strong><em> Makes the components easy to test, allowing us to move fast with confidence!</em></p><p><strong><em>Alternatives (to Jest):</em></strong><em> </em><a href="https://github.com/mochajs/mocha"><em>Mocha</em></a></p><p><strong><em>Why </em></strong><a href="https://github.com/facebook/jest"><strong><em>Jest</em></strong></a><strong><em> and </em></strong><a href="https://github.com/airbnb/enzyme/"><strong><em>Enzyme</em></strong></a><strong><em>:</em></strong><em> Tight support for React in Jest, and Enzyme’s amazing support for selectors and DOM traversal to easily target elements and use simple jQuery-like syntax made it a no-brainer to go with this setup.</em></p><h4><a href="https://github.com/nfl/react-helmet">Helmet</a></h4><p>A super-simple helper library to manage your &lt;title&gt; and &lt;meta&gt; tags (description, keywords, etc.) for your app. It’s the simplest (see <a href="https://github.com/nfl/react-helmet">examples</a>), most popular library for doing this, so if you’re interested in managing and updating your document head from within the React app, you should <a href="https://github.com/nfl/react-helmet">get it</a>.</p><h3>So, how did it work out?</h3><p>At Opendoor, we’ve been enjoying a successful move to React using the stack described above for couple months now. We’ve slowly validated these choices and now feel pretty confident in them.</p><p>The small chunk that we started out with has already started expanding into the rest of our codebase and is taking over the app! 🚀</p><p>Things aren’t all sunshine and rainbows though — here are a couple of tradeoffs to be aware of:</p><ul><li>All these packages together introduce a lot of boilerplate code that you must write every time you want to expand functionality of the app, making the process tedious and error-prone.</li><li>Each package brings it’s own set of terminologies and philosophies to ramp up on, adding cognitive overhead and learning curve, resulting in a harder time onboarding new team members.</li><li>There’s some uncertainty in depending upon individual package owners publishing updates with backwards compatibility that doesn’t break the specific dependencies stack that you may have chosen.</li></ul><p>That said, we think the benefits outweigh the concerns. We’re seeing a marked improvement in our app’s performance, testability and reusability wins of being component-first, and overall scalability in the architectural design.</p><p>Hope you can benefit from the same!</p><h3>Next up…</h3><blockquote><strong>In </strong><a href="https://medium.com/opendoor-labs/using-react-in-a-production-app-implementation-guide-94ec249dc78b"><strong>part 2</strong></a>, we will get into the details of how to implement this stack and any gotchas to be aware of with each package.</blockquote><p><em>At </em><a href="https://www.opendoor.com/"><em>Opendoor</em></a><em>, we’re working with React and other technologies like this to build a world-class product that simplifies the process of buying and selling homes.</em></p><p><em>Come work with us! Find out more about Opendoor jobs on </em><a href="https://stackshare.io/opendoor#jobs"><strong><em>StackShare</em></strong></a><em> or on our </em><a href="https://www.opendoor.com/jobs"><strong><em>careers site</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cd552d058ad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendoor-labs/using-react-in-a-production-app-4cd552d058ad">Using React in a Production App</a> was originally published in <a href="https://medium.com/opendoor-labs">Open House</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>