<?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 Cory House on Medium]]></title>
        <description><![CDATA[Stories by Cory House on Medium]]></description>
        <link>https://medium.com/@housecor?source=rss-e986f7cdb458------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xB4CuCviTqfarnzs7QQESw.jpeg</url>
            <title>Stories by Cory House on Medium</title>
            <link>https://medium.com/@housecor?source=rss-e986f7cdb458------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 19 May 2026 04:00:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@housecor/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[What’s In My Laptop Backpack? Here’s the Hardware I Use...and Why.]]></title>
            <link>https://medium.com/@housecor/whats-in-my-laptop-backpack-here-s-the-hardware-i-use-and-why-ef0ef09e9b88?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef0ef09e9b88</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[travel-tips]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hardware]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Wed, 27 Jun 2018 14:15:55 GMT</pubDate>
            <atom:updated>2018-06-27T15:16:01.969Z</atom:updated>
            <content:encoded><![CDATA[<h4>I work while traveling the world. This tech makes it possible.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0W-WbjlrOPo8FhBW7lu6g.png" /><figcaption>My backpack isn’t light. But it’s useful.</figcaption></figure><blockquote><em>Disclaimer: I use Amazon affiliate links below.</em></blockquote><p>I enjoy the digital nomad lifestyle, so I often work on the road. I write code, do consulting, create presentations, and author courses. Here are the tools I bring along for the ride.</p><h3>My Backpack</h3><h4>MacBook Pro 15</h4><p>I preferred the old 2015 keyboard and don’t use the TouchBar. So why’d I buy this?</p><ul><li>The SSD is faster than the 2015.</li><li>It’s thinner and lighter than the 2015.</li><li>The screen is notably brighter, so I can easily work outside. (Apple’s anti-glare screen tech is much better than today’s mirror-like touchscreen displays)</li><li>TouchID is handy.</li><li>USB-C makes it easy to dock. I use <a href="https://www.amazon.com/gp/product/B00VU2K10G/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B00VU2K10G&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=291e8eeb79effcc46f5d2ea28337ec0f">Apple’s HDMI with USB and power dongle</a> when traveling. I put a few cheap <a href="https://www.amazon.com/Adapter-Hi-speed-Devices-MacBook-ChromeBook/dp/B01LXAUUTG/ref=sr_1_14?s=electronics&amp;ie=UTF8&amp;qid=1530105982&amp;sr=1-14&amp;keywords=USB-C+to+USB-A+adapter">USB-C to USB-A adapters</a> on existing USB-A peripherals.</li></ul><p><a href="http://Late 2016 MacBook Pro 15&quot; TouchBar 16GB 512GB -">My full review</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w5-oAI8-bGk05rLH.png" /></figure><h4>Verizon Mifi</h4><p><a href="https://www.amazon.com/gp/product/B076HSWM8S/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B076HSWM8S&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=7b0b11af6fbd2fb8af3080adc00c1c98">Verizon 7730L Mifi</a> — I’ve tethered to my phone for years, but it always annoyed me. Poor signal, slow speeds, quick battery drain, and it tied up my phone so I couldn’t do calls while online. This is so fast it feels almost like I’m home, the battery lasts 24 hours, and its been consistently fast and reliable everywhere I’ve used it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*pM3n8to5-kOBD9Kg.png" /></figure><h4>The Roost Stand</h4><p><a href="https://www.amazon.com/gp/product/B01C9KG8IG/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01C9KG8IG&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=8e0682612f1e7a965fb387d84c9581ae">The Roost laptop stand</a> — I absolutely love this thing. No more looking down at a screen. This avoids neck pain by placing the screen at eye level. It improves my mood too (looking down is a mental downer too).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4luFoNY1xwD2P5hp.png" /></figure><p>I use this on planes so I can read without being cramped. It fits nicely on a tray table. And since it places the machine above the tray table, it leaves room on the tray table for the separate trackpad and a drink.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dvq4WGmKik10C7v2.png" /></figure><p><a href="https://twitter.com/housecor/status/795376644437446657">Related tweet</a> <br><a href="https://twitter.com/housecor/status/761533014002241536">Another related tweet</a></p><h4>Apple Airpods</h4><p><a href="https://www.amazon.com/gp/product/B01MQWUXZS/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01MQWUXZS&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=3eeec382dc3aa95ac48e6ca1a3e7fd8c">AirPods</a>. These sound fantastic and are so comfortable I forget they’re in my ears. I like how they pause when I remove one, and a double tap on the side switches to the next track. I bought silicon covers for biking but found they’re not necessary — I’ve never had one fall out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4hTybb1vhuZKM3BZ.png" /></figure><h4><a href="https://www.amazon.com/gp/product/B0756CYWWD/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B0756CYWWD&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=e8b0a431ed5bf2a306913ed07d9e7c48">Bose Headphones</a></h4><p><a href="https://www.amazon.com/gp/product/B0756CYWWD/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B0756CYWWD&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=e8b0a431ed5bf2a306913ed07d9e7c48">Bose QC35 Noise Cancelling Headphones</a> — I mostly use these on planes and in loud environments. They do an excellent job at cutting noise on flights, noisy airports, and team rooms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DIV017iCXAGLR4u1.png" /></figure><h4>Apple Magic Trackpad 2</h4><p><a href="https://www.amazon.com/gp/product/B016QO5YWC/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B016QO5YWC&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=27e5318b8f201d181d64c54f6601ee79">Magic Trackpad 2</a> — I was surprised to fall in love with this. Using a built in trackpad on a laptop can lead to hand cramps, but that’s just because of the awkward wrist angle they tend to create when a laptop is on your lap. Since this is placed in a normal mouse location, I find it very comfortable. I like being able to use the same gestures as on my MacBook’s trackpad. So my workflow doesn’t change when I dock. And since I can place my hands however I like, I find it very comfortable. Also, since I travel a lot, being able to just sit this on any surface is a win — unlike a mouse which can be picky about surfaces. It’s flat and light, so it fits easily in my bag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*SYmmQUPBY0Dbf3yV.png" /></figure><h4>Apple Magic Keyboard 2</h4><p><a href="https://www.amazon.com/gp/product/B01NABDNPH/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01NABDNPH&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=ff43f4604dc5518f896ef36be0297901">Magic Keyboard 2</a> — The worst thing about the new MacBook Pros is the keyboard. The Magic Keyboard 2 has the same key feel as the old MacBook laptops. 👍 And since I like to use my machine on the Roost stand, I need an external keyboard. This is flat, light, wireless, and durable, so it’s perfect for travel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9Llg2bYYsDGk8RHW.png" /></figure><h4>Logitech Presenter</h4><p><a href="https://www.amazon.com/gp/product/B002GHBUTU/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B002GHBUTU&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=c503780393a59d5d31445056d66fbf94">Logitech R800 Wireless Presenter</a> — I like this because it has a countdown timer, long battery life, and excellent range. Pro tip: Here’s how I avoid forgetting to start the countdown timer: I start the countdown timer before the talk begins. I just set the timer to the length of the talk plus the number of minutes until the talk begins. (so if it’s an hour long talk and I’m starting the timer 15 minutes before the talk, then I set the timer to an hour and 15 minutes and press start).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/0*3_yXfQPgJ0B6K2IF.png" /></figure><h4>Anker Battery</h4><p><a href="https://www.amazon.com/gp/product/B0194WDVHI/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B0194WDVHI&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=11d644224925d782ffe6f074d3f61432">Anker Powercore 10000 USB Battery</a> — This 10,000 mah battery has enough juice to charge my phone, headphones, and Verizon Mifi multiple times so I don’t worry about running out of juice. And it’s about the size as a deck of cards!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*CYyMz-jJUXh_m7Ko.png" /></figure><h4>Apple iPhone 7</h4><p>I’ve had Android for years but recently switched because iPhones benchmark significantly faster. Performance is the most important feature to me, and so far this has been quite snappy. I also like iPhone’s integration with Mac. It’s handy getting text messages and calls forwarded to my Mac so I can leave my phone plugged in outside my office which aids focus.</p><p><strong>Other items in my backpack</strong>:</p><ul><li>Outdoor coding kit: Hat, sunglasses, and sunscreen</li><li>Airport/coffee shop kit: Plugin adapters (useful so I can share an outlet with others), an extension chord (again, useful when I can’t get close enough to an outlet)</li><li>Sleeping kit: Mask and earplugs for sleeping on airplanes</li><li>International travel: Not pictured, but I bring a couple of these <a href="https://www.ebay.com/itm/Worldwide-Universal-AC-Power-Plug-World-Travel-Adapter-International-Converter/263773779684?hash=item3d6a2476e4:g:EtMAAOSw1URav9Jy">universal AC power plug adapter</a> when traveling internationally.</li><li>USB to lightning cable — For charging phone, AirPods, Trackpad, keyboard. The benefit of using all Apple is I can use the same cable to charge all 4 of these wireless peripherals.</li><li>Second monitor in a pinch: I carry a 6&#39; HDMI cable. Handy when a conference is lacking one. I also use it to attach my machine to the hotel TV so I can enjoy a second monitor on the road. <a href="https://hackernoon.com/why-i-stopped-using-multiple-monitors-bfd87efa2e5b">I typically prefer a single monitor</a>, but this is useful when video conferencing so I can put the video call on one screen and work on the other. Sometimes I put concerts on the 2nd screen so I don’t feel so alone in hotels. :)</li></ul><p>Here I’m using the hotel TV as a 2nd monitor via HDMI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QkpSjdwevyxackcZ.png" /></figure><h3>Hardware I use at Home</h3><p>Here’s the equipment I use at home.</p><h4>Dell 27&quot; 4K Monitor</h4><p><a href="https://www.amazon.com/gp/product/B073VYVX5S/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B073VYVX5S&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=0a5764f9875242779b06c7eeb1af76e6">Dell P2718Q 27&quot; 4K Monitor</a> — I love this display. Perfect size, beautiful IPS panel, and attractive small bezel design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*htme5vhHrNzakMvj.png" /></figure><p><a href="https://twitter.com/housecor/status/901812207654227968">My tweet about it</a></p><h4>Monoprice USB-C Adapter</h4><p><a href="https://www.amazon.com/gp/product/B01EMEBT7M/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01EMEBT7M&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=21cb4fd4a903052d7498724e35af9185">Monoprice USB-C to 3x USB-A 3.0, Gigabit Ethernet &amp; USB-C Adapter</a> — When I get home, I dock my Mac with this. The only other cable I plug in is the USB-C cable running out of my 4K monitor. I have Google Fiber, so it’s great plugging this thing in and enjoying gigabit speeds! 🏎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iJapl_ElN779oWmH.png" /></figure><h4>Veridesk Pro</h4><p><a href="https://www.amazon.com/gp/product/B00JI6NCCK/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B00JI6NCCK&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=1c8a961241aa2a9a90ccd7aefbfde1c4">Veridesk Pro Adjustable Stand Up Desk Converter</a> — I placed this on top of a traditional desk so I can stand when desired.</p><h4>Lifespan Treadmill Desk</h4><p><a href="https://www.amazon.com/gp/product/B009QHLWUK/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B009QHLWUK&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=8eafff8eca513b199dcb54540c157e07">Lifespan TR1200 DT Treadmill</a> — I enjoy walking while working. Studies show <a href="https://bigthink.com/ideafeed/treadmill-desks-boost-memory-among-workers">walking while reading improves focus memory retention</a>. I find it also keeps me alert. I alternate between walking, standing, and sitting depending on my mood. When I want to sit, I wheel this back, put my chair in front of the desk, and collapse the Veridesk to sitting mode by pulling two levers to lower it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VAG3Xo-LCcU1ecX7.png" /></figure><h4>Sculpt Keyboard</h4><p><a href="https://www.amazon.com/gp/product/B00CYX26BC/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B00CYX26BC&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=7d02bd289a1474cc55522c4abdf12cbd">Microsoft Sculpt Keyboard</a> — I love this keyboard. Best keyboard action I’ve found, and the ergonomic design is quite comfortable. I’ve used it when traveling too but switched to a Magic Keyboard 2 because the Sculpt isn’t flat which bloats my backpack, and it’s small F-keys tend to get jammed down when it’s stuffed in a backpack (the sole downside I’ve found). I like that this keyboard comes with a separate number pad. This way the reach from the keyboard to the mouse is shorter. 👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0jEQ4bTxfImbUYEm.png" /></figure><h4>Apple Magic Trackpad 2</h4><p><a href="https://www.amazon.com/gp/product/B016QO5YWC/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B016QO5YWC&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=27e5318b8f201d181d64c54f6601ee79">Magic Trackpad 2</a> — Yes, I like this so much that I have a second for home.</p><h4>Ergotron Monitor Arms</h4><p><a href="https://www.amazon.com/gp/product/B0036RDOT8/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B0036RDOT8&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=c73ecc80cd8986aa45220d2179f77947">Ergotron Dual Monitor Arms</a> — I put my Dell 27&quot; on one, and my Mac on the other using the <a href="https://www.amazon.com/gp/product/B000ECUMTS/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B000ECUMTS&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=f4c9681df775ccb02f8c4fa7ea5f8757">Ergotron laptop tray</a> which attaches to the monitor arm. I typically only open my Mac for video conferencing since I prefer a single monitor setup. I run them side-by-side, but these arms support stacking too. I bought the stacking style since it gives you more vertical height adjustment for side-by-side arrangements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-5zaS60o-y_wvKrx.png" /></figure><h4>Rode Podcaster Mic</h4><p><a href="https://www.amazon.com/gp/product/B000JM46FY/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B000JM46FY&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=af4042847d40f78debac334a91081950">Rode Podcaster</a> attached to a <a href="https://www.amazon.com/gp/product/B001D7UYBO/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B001D7UYBO&amp;linkCode=as2&amp;tag=bitnatcom-20&amp;linkId=e72319bea182908e010318970f3927b6">Rode Boom Arm</a>. — I recorded <a href="https://app.pluralsight.com/profile/author/cory-house">all my Pluralsight courses</a> and podcasts on this mic. The USB interface makes it easy to work with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pZtyhXIgcCrG-Rkp.png" /></figure><h3>One More Odditity</h3><p>My wife makes fun of this, but I occasionally work from the car too. So I use a <a href="https://www.ebay.com/itm/Auto-ipad-Car-laptop-tablet-notepad-Steering-Wheel-N-Desk-vehicle-tray-stand/291113690883?_trkparms=aid%3D444000%26algo%3DSOI.DEFAULT%26ao%3D1%26asc%3D52475%26meid%3Df5e36925b35f40acb9f0c5490e2258a8%26pid%3D100752%26rk%3D1%26rkt%3D3%26mehot%3Dag%26sd%3D291958740726%26itm%3D291113690883&amp;_trksid=p2047675.c100752.m1982">steering wheel desk from eBay</a>. This is handy when I’m waiting for the kids while they’re at practice and events. I drop them off and wait there instead of driving back and forth. So this saves time and money. On nice days, it’s also enjoyable to drive somewhere inspiring and quiet so I can work from there for awhile. This works better than you might think. I find I can type just fine, and the screen is at eye level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AMWZ-opKEsAZlF45.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TYd6bAKNWtmsl6D2.png" /></figure><p><a href="https://twitter.com/housecor/status/833862725889572867">Related tweet with more pics</a></p><h3>Other ideas?</h3><p>Know of other good hardware I should consider? Please post a comment!</p><p>Cory House is the author of multiple courses on JavaScript, React, clean code, .NET, and more on <a href="http://pluralsight.com/author/cory-house">Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect, Microsoft MVP, and trains software developers internationally on front-end development practices. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef0ef09e9b88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yep, JavaScript Moves Fast. Build Your Component Library Anyway.]]></title>
            <link>https://medium.com/@housecor/yep-javascript-moves-fast-build-your-component-library-anyway-a50576ab3031?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/a50576ab3031</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Fri, 06 Apr 2018 13:05:16 GMT</pubDate>
            <atom:updated>2018-04-19T12:07:03.586Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JFxS_dW4owpFE2ZvJyk1Zw.png" /></figure><p>Here’s a question I’ve heard a few times recently:</p><blockquote>“What if we create a component library in React/Vue/Angular/whatever and a new component technology replaces it?”</blockquote><p>That’s not a question of if. It’s a question of when. These technologies have become wildly popular, but they’re not the end game. Like all technologies, something better will eventually come along and replace them.</p><p>But that fact is largely irrelevant. Establishing a library of reusable components for your company today remains absolutely critical.</p><p>Here’s why.</p><h3>Move Faster Today</h3><p>Reusable components help your team move faster by creating higher level abstractions. Components eliminate decision fatigue by programmatically enforcing a standardized approach. Just consider an opinionated form TextInput component.</p><p>It can eliminate all the following decisions:</p><ol><li>Should I put the label above the input or beside it?</li><li>Should I display validation errors to the right or below the input?</li><li>What color should the error be?</li><li>How should I mark required fields?</li><li>Should I validate required fields on blur or upon submit?</li><li>How much padding should I place between the label and the input?</li></ol><p>The list goes on. These aren’t questions your designers and developers should be asking every time they create a new form.</p><h3>Enforce Consistency</h3><p>Reusable components enforce user interface consistency. Your company likely has many developers. Yet your job is to build an app that <strong>looks like it was built by one developer.</strong></p><p>To do that, it’s critical to use reusable components. Copy/paste isn’t a design pattern. If designers and developers have the freedom to start from scratch again and again, your application will quickly become a patchwork of different looks, feels, and technologies.</p><h3>Improve Performance</h3><p>In a client side rendered app, every time you use a component you improve performance. Why? Because it minimizes the application’s bundle size and memory footprint. Using a component a second time <strong>requires no additional download, and hardly any extra memory</strong>.</p><p>Without a component library, your team is highly likely to include duplicate JavaScript that solves the same problems in slightly different ways which will bloat the bundle and slow performance. Even worse, they’re likely to grab another competing library and thus require users to download multiple full libraries that do the same thing.</p><h3>Less Maintenance</h3><p>More code leads to more maintenance. More maintenance leads to higher costs and more people which creates additional communication overhead that slows you down even further. Reusable components minimize the amount of code you need to create and maintain today.</p><h3>Easier Updates Later</h3><p>Finally, yes, eventually the component tech you’re using today is going to be legacy. But by creating a reusable component library today, you minimize the surface area that needs updated later.</p><p>It’s far easier to migrate a carefully componentized app because you can replace existing components one component at a time. That’s not so easy when your application is a patchwork of different technologies and patterns. Reusable components minimize the surface area you’ll need to update later.</p><h3>Low Investment</h3><p>A component library doesn’t actually require that much work. For instance, if you choose React, you need not, (and typically shouldn’t) start from scratch. There are <a href="https://github.com/enaqx/awesome-react#components">literally dozens of mature component libraries</a> to choose from and 100’s of standalone components as well.</p><p>Use a popular component library as your starting point and tweak it to your needs. Trust me, this need not take long and the benefits are significant.</p><p>Alternatively, you could choose to create plain CSS components as your foundation. An example of this approach is <a href="https://stackoverflow.design">Stacks from StackOverflow</a>. The advantage to this approach is twofold:</p><ol><li>If you move to a new technology in the future, the plain CSS foundation that you’re using behind the scenes in your JavaScript components can be reused.</li><li>If your company is currently using multiple component approaches such as React, Angular, and/or Vue, then this CSS approach can be used as the foundation for all.</li></ol><p>The disadvantage? You have to build your components from scratch so that they utilize your plain CSS component foundation.</p><p>My preference? Leverage an existing JavaScript component library as your foundation to minimize the amount of code you need to write to get rolling.</p><h3>Summary</h3><p>Don’t let the rapid innovation in JavaScript scare you away from investing in a reusable component library for your company. Yes, today’s technology will eventually be replaced, but change is the only constant in technology. For all the reasons above, reusable components are worth embracing today.</p><p>Looking for more details on how to get this done? I recently published “<a href="https://app.pluralsight.com/library/courses/react-creating-reusable-components/table-of-contents">Creating a Reusable React Component Library</a>” on Pluralsight. (<a href="https://help.pluralsight.com/help/free-trial-10-days-andor-200-minutes">free trial</a>)</p><h3>Looking for More on React? ⚛️</h3><p>I’ve authored <a href="http://bit.ly/psauthorpageimmutablepost">multiple React and JavaScript courses</a> on Pluralsight.</p><figure><a href="https://www.pluralsight.com/authors/cory-house"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*BkPc3o2d2bz0YEO7z5C2JQ.png" /></a></figure><p>Cory House is the author of multiple courses on JavaScript, React, clean code, .NET, and more on <a href="http://pluralsight.com/author/cory-house">Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect, Microsoft MVP, and trains software developers internationally on front-end development practices. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a50576ab3031" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to handle environment-specific settings in your JavaScript apps]]></title>
            <link>https://medium.com/@housecor/environment-settings-in-javascript-apps-c5f9744282b6?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5f9744282b6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Tue, 03 Apr 2018 23:56:52 GMT</pubDate>
            <atom:updated>2018-05-01T15:50:18.443Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sS6KcsjhHDEI1T0ka164Wg.jpeg" /><figcaption>Modern web apps have gotten…complicated.</figcaption></figure><p>Today many web apps are built using React, Angular, Vue, Ember, and others. These modern client-side rendered apps often call web APIs that are hosted on separate servers. This creates a problem: how do you configure your app to call the right API URL in each environment?</p><p>For example, during development, you may host the API locally at localhost:3000. In production, the API may be be hosted on some other server at api.mycompany.com. So you need your app to call localhost:3000 in development and api.mycompany.com in production. But how?</p><p>And the base URL is just one example of settings that may change per environment. You might choose to tweak other settings per environment for performance, security, or logging purposes. Some of the approaches below are applicable for these general environment-specific configurations as well. But for simplicity<strong>,</strong> this post focuses on techniques for configuring base URLs per environment.</p><p>I posted a poll on Twitter with a couple options:</p><h3>Cory House 🏠 on Twitter</h3><p>📊Poll: How do you configure your client-side rendered apps to call different API URLs in each environment? Example: Dev api runs on localhost:3002 Prod api is at https://t.co/8ZSpUMQi4m</p><p>Turns out, there are many ways to handle this. I received many insightful replies in the tweet thread. I’ve summarized eight options below. I’ve ordered these options (loosely) in the order that they should be considered. So, if you’re in a hurry, the options to consider first are at the top. 😀</p><h3>Option 1: Host the API with the app</h3><p>Simple. Just host the app and API from the same webserver, so relative URLs work everywhere. This avoids both the base URL issue as well as cross-origin problems.</p><h4><strong>When to consider it</strong>:</h4><ul><li>Your API is consumed by a single app.</li><li>You don’t need to scale your API and app separately, so hosting on the same server is practical.</li></ul><h3>Option 2: Environment-Specific Build</h3><p>This approach honors the compile-time maxim:</p><blockquote>“Never do at runtime what you can handle at compile time.”</blockquote><p>With this approach, you typically use a continuous integration (CI) server to generate and deploy custom builds for each environment. This is a powerful, secure, and versatile approach, but it requires each developer to create and maintain a .env file on their machine. <a href="https://medium.com/@rafaelvidaurre/managing-environment-variables-in-node-js-2cb45a55195f">Here’s a great post with some tricks for making this pretty painless</a>.</p><h4><strong>When to consider it:</strong></h4><ul><li>You’re comfortable configuring a CI server to automate the build and deployment process to assure reliability.</li><li>You want to significantly alter the code deployed to production, such as removing code that is only used in non-production environments for performance or security reasons.</li><li>You’re comfortable with the risk that comes along with deploying different code to production than the code you ran during development and QA.</li></ul><h3>Option 3: Runtime Configuration</h3><p>With this approach, you configure your app for each environment by referencing the relevant configuration data upon startup (as opposed to upon build as discussed above). So <strong>unlike the approach above, with this approach the same code is deployed to all environments</strong>. The configuration data you pass in on startup customizes the app’s behavior.</p><p>There are a couple potential ways to pass environment configuration data in:</p><ol><li><strong>Command line config</strong> — Pass the config in when starting the app.</li><li><strong>Environment config file</strong> — Populate a .env file in each environment and read from it upon startup. <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables">Here’s an example from the create-react-app docs</a>, but the approach applies to any JavaScript app.</li></ol><p>But how does your app get this info? There are a couple ways to do that, too:</p><ol><li><strong>Config file</strong> — Write the config data to a separate JavaScript file on app startup. Your app can import and read this file on startup.</li><li><strong>Global in index.html </strong>— Write the config data to a global in index.html using your build tool. Again, <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#injecting-data-from-the-server-into-the-page">here’s an example from the create-react-app docs</a>, but the approach applies to any JavaScript app.</li></ol><p>Admittedly, these approaches slightly change your code on startup based on the runtime configuration provided. But they’re different than option #2 above, because the same code is deployed to all environments.</p><h4><strong>When to consider it:</strong></h4><ul><li>You prefer to deploy the same code to all environments.</li></ul><h3>Option 4: Reverse Proxy</h3><p>With this approach, you call the same relative URL in all environments. How does that work? Well, it’s the front-end web server’s responsibility to forward calls to the relevant API for each environment. There are multiple benefits to this approach:</p><ol><li>Your URLs in all your API calls are clean, relative URLs. For example /user.</li><li>You can configure your front-end web server as a caching layer for added performance.</li><li>This approach supports switching back-end systems by simply re-configuring the proxy.</li></ol><h3>Eric Elliott on Twitter</h3><p>@housecor I always use relative /api path. Then let the web servers reverse proxy that wherever it needs to point to. No code changes or conditional logic required.</p><h4><strong>When to consider it:</strong></h4><ul><li>You have the ability to configure the web server in all environments</li><li>You’re interested in implementing a caching layer between your UI and your API.</li><li>Your front-end web server can forward calls to your API server reliably and quickly. There is a performance cost to this approach, since your web server must pass requests on to another server.</li></ul><h4><strong>Side note</strong>:</h4><p>While we’re talking about proxies, another proxy approach worth mentioning is proxy middleware (this is a totally different approach than the reverse proxy discussed above).</p><p>With proxy middleware running on your local machine, requests are forwarded to a specified URL during development. For instance, if you’re a React developer, <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#proxying-api-requests-in-development">create-react-app has proxy support built in</a>. It uses Webpack’s proxy middleware.</p><p>Here’s a <a href="https://medium.freecodecamp.org/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0">solid overview of the proxy approach</a> using React and Express.</p><p><strong>However</strong>: Proxy middleware only solves the base URL problem in development. So use one of the other techniques in this post to handle other environments such as QA and production.</p><h3>Option 5: Docker</h3><p>With Docker you can deploy the UI and API as separate containers, but create a “LAN” that allows the containers to communicate as though they’re on the same network. This way, the base URLs don’t change in each environment. The containers run identically in all environments. And you can pass relevant environment variables into the containers in each environment. Look into Kubernetes or Docker Swarm for this approach.</p><h4><strong>When to consider it:</strong></h4><ul><li>You’re already invested in the Docker ecosystem.</li></ul><h3>Option 6: Environment Sniffing</h3><p>With this approach, you use code to “sniff” 👃🏻 the current environment, typically by looking at the URL. For example, if the URL is http://localhost, you know you’re in development.</p><p>The benefit of this approach is simplicity. Developers don’t need to configure anything on their machine and you don’t need to monkey with CI server or web server configurations either.</p><h4><strong>When to consider it</strong>:</h4><ul><li>You have a simple app that calls a small number of APIs.</li><li>You don’t have a CI-server.</li><li>Your company politics make it painful or impractical to implement the other options above.</li><li>You’re not concerned about people potentially finding the URLs to your non-production environment. (For security, your non-production environment shouldn’t be accessible outside your corporate LAN/VPN anyway).</li></ul><h3>Option 7: Custom HTTP header</h3><p>Configure the front-end web server to provide a custom HTTP header that contains the relevant client URL for the environment. The downside of this approach is your app has to make an HTTP call to this API first to determine what the relevant base URLs are for all environments.</p><h4><strong>When to consider it:</strong></h4><ul><li>I don’t recommend this approach, since it requires your app to make a round trip HTTP call before it can actually begin fetching data. I prefer one of the other approaches above.</li></ul><h3>Option 8: App Config Endpoint</h3><p>With this approach, your app calls the same “app config” API at the same URL, for all environments. Your app calls this API first. The API call returns the relevant base URL in each environment (as well as potentially including other environment-specific settings). With this approach, you can potentially pass along with other relevant environment-specific config data.</p><h4><strong>When to consider it</strong>:</h4><ul><li>I don’t recommend this approach either. It impacts load time, because the initial HTTP call to retrieve config data must complete before the app can actually get started retrieving desired data. Consider one of the other options above instead.</li></ul><h3>Summary</h3><p>Create a build per environment via a CI server if you need true per-environment customization (#2 above). If you prefer deploying the same code to each environment, consider runtime configuration (#3 above) or a reverse proxy (#4 above).</p><p>Happy coding! ⌨️</p><p>Have other ways you handle this? Please chime in via the comments.</p><p><a href="https://twitter.com/housecor">Cory House</a> is the author of <a href="http://pluralsight.com/author/cory-house">multiple courses on JavaScript, React, clean code, .NET, and more on Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect, Microsoft MVP, and trains software developers internationally on front-end development practices. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5f9744282b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[32" 4K USB-C BenQ EW3270U Monitor Review]]></title>
            <link>https://medium.com/@housecor/32-4k-usb-c-benq-ew3270u-monitor-review-28326846cdd4?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/28326846cdd4</guid>
            <category><![CDATA[computers]]></category>
            <category><![CDATA[computer-hardware]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Thu, 29 Mar 2018 03:07:36 GMT</pubDate>
            <atom:updated>2018-07-31T11:12:38.418Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q8TEm5WHo8AE9pjJirY2-g.jpeg" /><figcaption>Uh, this isn’t my desk. But it is the monitor I’m reviewing.</figcaption></figure><p><strong>Disclaimer</strong>: BenQ gave me this monitor for free in exchange for this review. That said, as you’ll see these are my honest impressions.</p><p>As a software developer, I’ve run 2 or 3 monitors for years. But a few years ago <a href="https://hackernoon.com/why-i-stopped-using-multiple-monitors-bfd87efa2e5b">I realized I preferred using a single display</a>. The question is, what’s the perfect single display? I currently use a <a href="http://www.dell.com/en-us/work/shop/dell-24-ultra-hd-4k-monitor-p2415q/apd/210-agnk/monitors-monitor-accessories">24&quot; Dell 4K</a> in the office and a <a href="http://www.dell.com/en-us/shop/dell-ultrasharp-27-4k-monitor-u2718q/apd/210-amlm/monitors-monitor-accessories">27&quot; Dell 4K</a> at home. BenQ offered me their new <a href="https://www.amazon.com.au/dp/B07BBRLTRH?tag=commconn_au_1017-22">EW3270U 32&quot; 4K display</a> with USB-C in exchange for writing an honest review.</p><h4>Size</h4><p>Wow, this thing is big. At 32&quot;, it’s large enough to run the native 3840x2160 resolution. Doing so creates a massive desktop with small, crisp text.</p><p>To give you a sense of how much real estate you get, you can easily split the screen into 4 pieces and have plenty of room in each window to work comfortably.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lGqgjDI97_-1wIwMMuWSVg.png" /><figcaption>Look at all the white space around the medium post, even with the screen split in half!</figcaption></figure><p>In fact, there’s enough real estate to comfortably display 6 windows!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7brfw4GdFDpniGwwp6eVsg.png" /></figure><p>However I find text at the native resolution too small for comfort. Most will find 2560x1440 more practical. This is still a sufficient width to comfortably run windows side-by-side. However, this resolution isn’t as sharp. Why? Because math. Since 2560x1440 isn’t evenly divisble by the native resolution, it requires scaling. So you have to sacrifice a bit of text clarity and performance for the increased real estate. MacOS even warns you that these intermediate resolutions may impact performance (due to scaling overhead):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZbxrDIjw4l-rggcw2P-vMQ.png" /><figcaption>Note “Using a scaled resolution may effect performance” warning when selecting 2560x1440.</figcaption></figure><p>To avoid scaling, you have to run either the native resolution or 1920x1080, which is conveniently 1/4 the native resolution, so scaling isn’t required.</p><p>I currently run both my 27&quot; and 24&quot; Dell 4K displays at 1920x1080 to avoid scaling. At 1920x1080, text is huge on this 32&quot;, but it’s also crisp and <em>very</em> easy on the eyes. Although this display’s PPI is only 140, the text looks about as sharp as my 27&quot; and 24&quot; 4K displays.</p><h4>Stand</h4><p>The stand is sturdy and tilts, but unfortunately lacks height adjustment, rotation, and cable management. The good news is the stand sits at a natural height for a traditional desk. My eyes sit in the upper third which is the recommended height. That said, I suspect many will attach this to a VESA mount.</p><h4>Panel</h4><p>There are three common LCD panel technologies: TN, VA, and IPS.</p><p>Here’s a summary:<br><strong>“VA</strong> panels provide a good middle ground with better-than-<strong>IPS</strong> refresh rates and contrast levels, but have worse viewing angles and color production, although generally still better than TN. Response times are <strong>VA’s</strong> largest downfall, though, being slower than <strong>IPS </strong>and its variants and TN.” — Michael Kerns</p><blockquote><a href="https://www.gamersnexus.net/guides/1890-panel-comparison-tn-ips-pls-va-crt">More here</a>.</blockquote><p>This is a VA panel, so the viewing angles and color fidelity aren’t as good as my IPS Dell 27&quot;, but the refresh rate and contrast is better. I prefer IPS panels, but this is a solid VA panel with a subtle matte finish that is effective at handling glare yet subtle enough that it doesn’t seem to degrade the picture.</p><p>Unfortunately, at my standard viewing distance, the colors on the edges fade slightly compared to the middle. And that’s the core problem with using a VA panel at this size: The edges are far enough away that the viewing angle limitations are visible on the sides — even when viewed from the sweet spot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IblNInQ4KCZf_LS3-NjfBw.jpeg" /><figcaption>Note how the edges are slightly lighter.</figcaption></figure><p>On my IPS displays, colors and brightness are uniform.</p><p>That said, unless you’re doing image critical work such as editing photographs, this is a minor annoyance in most real world cases. It’s unlikely to bother you if you’re used to TN or VA panels.</p><h4>Design</h4><p>This BenQ design is clean enough, but not as modern as some competitors. For example, my Dell U2718Q has a panel that is flush with the bezel (rather than inset), and bezels that are less than half as wide as the BenQ display’s. And given the BenQ’s bezel size, it’s disappointing a webcam isn’t included.</p><h4>I/O</h4><p>I was excited to see this monitor provides USB-C, and the included USB-C cable displays at 60hz as expected. However, there are two notable issues with this monitor’s USB-C implementation:</p><ol><li>No power is passed over USB-C. This is a big disappointment given competitors like LG do so. <a href="https://www.benq.com/en/monitor/designer/pd2710qc.html">Other BenQ displays provide power as well</a>. Without USB-C charging, you can no longer enjoy a single cable hookup experience.</li><li>No daisy chaining support. You can’t connect another display to the back of this one. Again, this is supported on other USB-C monitors and <a href="https://www.benq.com/en/monitor/designer/pd2710qc.html">some BenQ displays</a>.</li><li>There are no USB inputs, which greatly reduces the usefulness of the USB-C input.</li></ol><p>Bottom-line, this monitor’s USB-C input is redundant. The DisplayPort 1.4 port is also capable of displaying 4K@60hz, so one could simply buy a USB-C to Displayport cable if they have a USB-C machine and get the same experience. So unfortunately, I see no benefit to this monitor including USB-C.</p><p>Two HDMI inputs are also included, as well as a headphone jack.</p><h4>Speakers</h4><p>The included 2 watt speakers get loud enough, but sound thin. My Macbook Pro’s built in speakers are clearer and equally loud. Shoot, even my iPhone 7’s speaker sounds notably better and reproduces a greater frequency range. That said, most monitors don’t include speakers, so having this in a pinch is a nice touch.</p><h4>Eye Care</h4><p>This monitor also includes BenQ’s B.I.+ (Brightness Intelligence Plus), which adjusts the backlight and color temperature based on the environment. This feature works well and I’ve found it useful. I often work in a dimly lit room at night and very bright room with many windows during the day. This display is looks great in both extremes and I don’t have to fiddle with any settings. And much like my MacBook Pro, the brightness changes are gradual so they’re not jarring. Turn out the lights and it subtly dims over a short period. Nice.</p><p>BenQ promotes other eye care features on this monitor including a “low blue light” setting which filters out blue light that can cause eye strain. The effect is subtle, but I will say the display is easy on the eyes and much more pleasant to look at than many harsh, bluish LCDs I’ve seen. Filtering blue light should help foster sleep in the evenings too.</p><h4>Other Unique Features</h4><p>This is an HDR display. I streamed 4K HDR content from Netflix and was very impressed with the results — it looks excellent. You can press the dedicated HDR button on the front of the panel to enable emulated HDR mode, which produces a brigther, bluer picture. This works well for video content. A second press on the front panel button enables the aforementioned B.I.+ feature.</p><p>“Super Resolution” claims to enhance the resolution of low quality images. I found it seems to operate like a sharpness control on a TV. Like my TV, I prefer to keep sharpness turned off since it creates visible artifacts in an effort to enhance edges.</p><p>“Smart Focus” grays out a portion of your screen so you can focus on a specific area.</p><h4>Price</h4><p>At $699, this display isn’t cheap. 32&quot; 4K displays are significantly pricier than 27&quot; competitors. The only 32&quot; 4K USB-C competitor I’ve found is the <a href="https://www.amazon.com/LG-32UD99-W-32-Inch-UHD-Monitor/dp/B06XDY3TXW">LG 32UD99</a> which is $999. For the extra $300, you get an IPS panel, smaller bezels, a height adjustable stand that rotates vertically, USB ports, more powerful speakers, and 60 watts of power over USB-C. But the LG display lacks the unique eye care features offered on this BenQ.</p><h4>Conclusion</h4><p>So who is this for? This monitor is a worth considering if one or more of these apply to you:</p><ul><li>You want a massive desktop for multi-tasking and are okay with small text. 32&quot; is arguably the bare minimum size for running native 4K.</li><li>You want to run two windows side-by-side at 2560x1440 and are willing to take a slight hit in text sharpness and performance due to scaling.</li><li>You want big, beautiful, crisp text with high contrast. This monitor touts unique eye care features, but perhaps the most significant eye care feature is the ability to display crisp content at a very easy-to-read size when run at 1920x1080.</li><li>You work in various lighting conditions and would thus appreciate the B.I.+ feature.</li><li>Your use cases don’t require an IPS panel’s superior viewing angles and color fidelity.</li><li>The lack of integrated USB ports doesn’t effect you because you’re using a desktop or your laptop has sufficient ports built in.</li></ul><p>If any of these points apply to you, the BenQ EW3270U is worth considering.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28326846cdd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Reusable React Components]]></title>
            <link>https://medium.com/@housecor/designing-reusable-react-components-1cbeb897b048?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cbeb897b048</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Sat, 30 Dec 2017 17:10:37 GMT</pubDate>
            <atom:updated>2018-01-09T17:05:28.522Z</atom:updated>
            <content:encoded><![CDATA[<h4>What Legos Can Teach Us About Reuse in React Apps</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CByHyzJRQR6G8aiAkdFwcQ.png" /></figure><p>React is a component library. So React makes it easy to break your UI down into composable pieces. The question is, <a href="http://sethgodin.typepad.com/seths_blog/2017/12/granularity.html">how granular should the pieces be</a>?</p><p>Let’s consider a specific example that I explored in a <a href="https://medium.freecodecamp.org/reusable-web-application-strategies-d51517ea68c8">previous post</a>.</p><p>Imagine your team just deployed a ToDo app, built in React. A month later, another team in your company wants to run your ToDo app within their invoice app, also built in React.</p><p>So now you need to run your ToDo app in two spots:</p><ol><li>By itself</li><li>Embedded within the invoice app</li></ol><p>What’s the best way to handle that? 🤔</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S3wRzzFKKlls9bTlSpFfKA.png" /></figure><p>To run your React app in multiple spots, you have three options:</p><ol><li><strong>iframe</strong> — Embed the todo app in the invoice app via an &lt;iframe&gt;.</li><li><strong>Reusable App Component</strong> — Share the entire todo app via npm.</li><li><strong>Reusable UI Component</strong> — Share the todo app’s markup via npm.</li></ol><p>Let’s discuss the merits of each approach.</p><h3>Approach 1: iFrame</h3><p>The easiest and most obvious approach is to use an <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe">iframe</a> to frame the ToDo app into the invoice app.</p><p>But leads to multiple issues:</p><ol><li>If the two apps display the same data, you risk them getting out of sync.</li><li>If the two apps use the same data, you end up making redundant API calls to fetch the same data.</li><li>You can’t customize the iframed app’s behavior.</li><li>If a different team owns the framed in app, when they push to production, you’re instantly affected.</li></ol><p>Bottom-line: Walk way. Avoid iframes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0YcpMhPGBRBeQ25G9g-iA.jpeg" /><figcaption>Nope.</figcaption></figure><h3>Approach 2: Reusable App Component</h3><p>Sharing your app via npm instead of an iframe avoids issue #4 above, but the other issues remain. API, auth, and behavior are all baked in. So I don’t recommend sharing full apps via npm either. The level of granularity is too high, so the user experience suffers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjvQ8XV65JcxIETD53CNDg.jpeg" /><figcaption>Like Lego blocks, reusable React components should be granular and composable.</figcaption></figure><h3>Approach 3: Reusable UI Components</h3><p>I recommend a more granular approach using two flexible building blocks:</p><ol><li>“Dumb” React components (Just UI. No API calls inside.)</li><li>API wrappers</li></ol><p>“Dumb” React components are configurable, unopinionated, and composable. They’re reusable UI. When consuming a “dumb” component like this, you are free to provide the relevant data or specify the API calls the app should make.</p><p>However, if you’re going to compose “dumb” components, you need to wire up the same API calls for multiple apps. This is where API wrappers come in handy. What’s an API wrapper? It’s a JavaScript file full of functions that make HTTP calls to your API. My team creates API wrappers. We use <a href="https://github.com/axios/axios">Axios</a> behind the scenes to make the HTTP calls.</p><p>Imagine you have a user API. Here’s how to create a user API wrapper:</p><ol><li>Create a JS file with public functions like getUserById, saveUser, etc. Each function accepts the relevant parameters and uses Axios/Fetch to make HTTP calls to your API.</li><li>Share the wrapper as an npm package called userApi.</li></ol><p>Here’s an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/287bab2e333fef51d6de28ee9ac80721/href">https://medium.com/media/287bab2e333fef51d6de28ee9ac80721/href</a></iframe><p>On my team, we share our React components and API wrappers as <a href="https://www.npmjs.com/pricing">private packages on npm</a>, but <a href="https://jfrog.com/artifactory/">Artifactory</a> is a nice alternative.</p><p>These Lego blocks give us the foundation for quickly building new solutions out of reusable pieces.</p><blockquote>A highly composable system provides components that can be selected and assembled in various combinations to satisfy specific user requirements. — <a href="https://en.wikipedia.org/wiki/Composability">Wikipedia</a></blockquote><p>So ideally, your “dumb” reusable UI component is composed of <a href="https://app.pluralsight.com/library/courses/react-creating-reusable-components/table-of-contents">other reusable components, also shared on npm</a>!</p><p>With reusable React components and API wrappers published to npm, it’s trivial to build something awesome.</p><p>It’s like snapping Lego pieces together. 👍</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FKi2C05my2K4%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKi2C05my2K4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FKi2C05my2K4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/439a02fd8bd96adc48ee65fd015120b0/href">https://medium.com/media/439a02fd8bd96adc48ee65fd015120b0/href</a></iframe><p>I explore the merits and downsides of the approaches above in more detail <a href="https://medium.freecodecamp.org/reusable-web-application-strategies-d51517ea68c8">here</a>. And I recently published a comprehensive course on <a href="http://bit.ly/legoreactps">Creating a Reusable React Component Library on Pluralsight</a>. 🎉</p><p>Have a different approach you enjoy? Chime in via the comments.</p><h3>Looking for More on React? ⚛️</h3><p>I’ve authored <a href="http://bit.ly/psauthorpageimmutablepost">multiple React and JavaScript courses</a> on Pluralsight (<a href="http://bit.ly/pstrialimmutablepost">free trial</a>).</p><figure><a href="https://www.pluralsight.com/authors/cory-house"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*BkPc3o2d2bz0YEO7z5C2JQ.png" /></a></figure><p><a href="https://twitter.com/housecor">Cory House</a> is the author of <a href="http://pluralsight.com/author/cory-house">multiple courses on JavaScript, React, clean code, .NET, and more on Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect, Microsoft MVP, and trains software developers internationally on front-end development practices. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cbeb897b048" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Year with the MacBook Pro TouchBar]]></title>
            <link>https://medium.com/@housecor/a-year-with-the-macbook-pro-touchbar-301a96f49c34?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/301a96f49c34</guid>
            <category><![CDATA[macbook]]></category>
            <category><![CDATA[review]]></category>
            <category><![CDATA[laptop]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Fri, 08 Dec 2017 15:42:13 GMT</pubDate>
            <atom:updated>2017-12-10T16:04:00.276Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I’ve learned to live with — even love — a flawed machine</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bELu9KWu_aK6hmbj76kmWg.jpeg" /></figure><p>I previously owned a 2015 13&quot; MacBook Pro, but purchased a 15&quot; Macbook Pro TouchBar in Nov. 2016. <a href="https://hackernoon.com/a-week-with-the-new-macbook-pro-with-touch-pad-126eebb89ac">I posted an initial review after one week</a>.</p><p>The results after one year? It’s been a mixed bag, but here’s the tl;dr:</p><p>There are keyboard and reliability issues, but all considered I prefer it over the 2015.</p><h4>The Good</h4><p><strong>Superb screen</strong> — For me, this is the most compelling reason to choose a Mac. I hear Apple has a patent on their screen glare reduction approach, and it shows. Every other laptop I’ve seen is hard to use in bright lighting because it’s like a black mirror — this issue is even worse on touchscreen machines.</p><p>On the new MBP, reflections are muted. Plus, the new MacBook screen is notably brighter — enough so that I can work sitting in the sun and easily read it. I love working outdoors with a hat on to keep the sun out of my eyes, so that’s a huge win. The result: I enjoy using the new MacBook Pro in my hammock. 🌴</p><p><strong>USB-C</strong> — Being able to plug any peripheral in from either side is wonderful. No more awkward cable routing. And cords are effectively a foot longer when you know you can plug in on the near side. I dock my machine with two cables. I use a <a href="https://www.monoprice.com/product?p_id=15250&amp;gclid=CjwKCAiAjanRBRByEiwAKGyjZRBnqACddOFABgm3YvhbFTY3tH2zFILFCtF2yOu2haORNBv1Gf1tZBoCeFEQAvD_BwE">Monoprice USB-C dongle</a> to connect Gigabit Ethernet, power, and three different USB peripherals. I use a second USB-C to Displayport cable to run a <a href="http://www.dell.com/en-us/shop/dell-ultrasharp-27-4k-monitor-u2718q/apd/210-amlm/monitors-monitor-accessories">Dell 27&quot; 4K Monitor</a> at 60hz. Yes, <a href="https://hackernoon.com/why-i-stopped-using-multiple-monitors-bfd87efa2e5b">I prefer running a single monitor</a>.</p><p>Side note, ❤️ this monitor:</p><h3>Cory House 🏠 on Twitter</h3><p>Just upgraded to 27&quot; 4K Dell. Love it! Compared to old 24&quot; 4K: -HDR -Richer colors, contrast -Flush, small bezel -Uses only 30W vs 90W! 👍</p><p>When traveling, I use <a href="https://www.apple.com/shop/product/MJ1K2AM/A/usb-c-digital-av-multiport-adapter?fnode=8b">Apple’s dongle</a> to display on projectors via HDMI.</p><p>I haven’t missed MagSafe for two reasons:</p><ol><li>I typically only plug in when at a desk where MagSafe is largely irrelevant.</li><li>USB-C dongles pass power through, so there’s now one less thing to connect. 👍</li></ol><p>With two USB-C connections, I’m docked.</p><p><strong>Sufficient battery life</strong> — Battery life hasn’t been a problem. It seems similar to my old 13&quot; as long as I avoid running the screen at high brightness. I typically get around 5 hours, though I often work outside or with the screen brightness cranked up. If you keep the screen brightness down, the battery life is seriously impressive:</p><h3>Cory House 🏠 on Twitter</h3><p>New 15&quot; MBP battery life is quite impressive in low light. After 5 hrs of reading &amp;amp; coding on a flight, got off with 74% battery life left!</p><p><strong>TouchID is (finally) awesome</strong> — This was initially unreliable, but an OS update made it rock solid and fast as the iPhone. Super handy.</p><p><strong>Larger Trackpad FTW</strong> — I’ve grown to love the new giant trackpad. I initially had issues with palm rejection, but an OS update fixed that. I tried using a 2015 MacBook Pro recently and the trackpad felt too small. I found myself hitting the edges. I was initially skeptical, but the giant trackpad is a win. And it’s natural that it’s the same size as my external Magic Trackpad 2.</p><p><strong>Great packaging</strong> — After a year of heavy travel, I have no regrets moving from a 13&quot; to the new 15&quot;. The 15&quot; is easily portable. I recently tried a 2015 15&quot; and the difference in thickness and weight was instantly noticable. The new 15&quot; is the first 15&quot; that’s thin and light enough for me to enjoy traveling with it.</p><p><strong>Cool and quiet </strong>— The fan virtually never comes on. The machine is consistently cool to the touch.</p><p><strong>Great speakers</strong> — The speakers continue to impress, though I typically wear <a href="https://www.apple.com/shop/product/MMEF2AM/A/airpods?fnode=cc5a9a755d420aab93da61817cfbf5fd979f464e94afbd2043caf09317593bd098c9d13ac5d97381b0e952cf05b3aef0ce9312e756dd9e9f4e20ff06a94ee98d6c2752c6460819133bcf8aa287a5251adb286adda49f0a4a575aa81d856fa8f57f437fd91bc0d614cf5912c77ed2fe2cf041a4866903c850673fa0e1be6b97ea">Airpods</a> for music and web-based meetings.</p><p><strong>Fast</strong> — Notably faster than my old 13&quot;. Likely attributable to the faster SSD.</p><h4>The Bad</h4><p><strong>Polarizing keyboard</strong> — Some rave about the new keyboard, but I’ve never warmed to it. It’s a step backward to me. The key action on the old keyboard is more comfortable and reliable. The travel is so shallow that I have to deliberately hit the keys gently or my fingertips hurt. The spacebar became unresponsive on 3–4 occasions. In each case, I fixed it by sliding my fingernail around the key. I assume debris was impeding key travel.</p><p>At one point there was something under the spacebar that impeded the key, but slapping the key and tilting the machine around fixed it.</p><p>Thankfully, I rarely use laptop keyboards. I prefer to keep the screen at eye-level via <a href="https://www.therooststand.com">The Roost</a> for better ergonomics.</p><h3>Cory House 🏠 on Twitter</h3><p>Pro tip: Bring an HDMI cable when traveling. Hotel TV makes a good 2nd monitor in a pinch! (2 displays required for @pluralsight recording)</p><p>When traveling, I typically use the <a href="https://www.amazon.com/Apple-Wireless-Keyboard-Silver-MLA22LL/dp/B01NABDNPH">Apple Magic Keyboard 2</a>, which has keys that feel like the old 2015 Macbook Pro. 👍 When home, I use the <a href="https://www.amazon.com/Microsoft-Ergonomic-Wireless-Desktop-Keyboard/dp/B00CYX54C0/ref=sr_1_4?s=electronics&amp;ie=UTF8&amp;qid=1512737035&amp;sr=1-4&amp;keywords=sculpt+keyboard">Microsoft Sculpt</a>. I use a <a href="https://www.amazon.com/Apple-Magic-Trackpad-2-MJ2R2LL/dp/B016QO5YWC/ref=sr_1_3?s=electronics&amp;ie=UTF8&amp;qid=1512737137&amp;sr=1-3&amp;keywords=magic+trackpad+2">Magic Trackpad 2</a> with both keyboards so I always have the same gestures available as when using the laptop directly.</p><p><strong>Touchbar = meh</strong> — It’s customizable, which is cool, but I typically use the machine with an external keyboard, so I rarely use the TouchBar. I would happily buy a machine with plain F keys and save the money and battery life.</p><p><strong>Stability</strong> — The machine is rock solid when running alone. But a small portion of the time, the machine will reboot upon connection to a USB-C dock while closed. I’ve learned to dock with the clamshell open and it works fine. Occasionally, the separate USB-C to monitor connection fails to display. In those cases, I plug into a different USB-C port and it works. Thankfully, both are rare, so I can live with it.</p><p><strong>Build quality issue</strong> — My machine was sporadically making popping noises near the hinge. <a href="https://discussions.apple.com/thread/7825434?start=30&amp;tstart=0">Many have reported the problem</a>. I reported it to Apple and the experience was very smooth. They shipped me a box so I could ship the machine in, and I had the machine back in about a week with the issue resolved under warranty. They even paid for next day air to return my device. This is the first quality issue I’ve had with an Apple product. To their credit, it was handled well.</p><h4>Summary</h4><p>The keyboard and docking stability are the key annoyances for me. I have workarounds for both, so given all the other wins, I’ve decided:</p><p>I’m keeping it.</p><p><a href="https://twitter.com/housecor">Cory House</a> is the author of <a href="http://pluralsight.com/author/cory-house">many courses on Pluralsight</a>, and principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>. He is a Principal Software Engineer at Cox Automotive, Microsoft MVP, and trains software developers internationally on software practices. Catch Cory on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=301a96f49c34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Pattern: Centralized PropTypes]]></title>
            <link>https://medium.com/@housecor/react-pattern-centralized-proptypes-f981ff672f3b?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/f981ff672f3b</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Tue, 14 Nov 2017 16:39:43 GMT</pubDate>
            <atom:updated>2018-04-19T20:51:25.154Z</atom:updated>
            <content:encoded><![CDATA[<h4>Avoid repeating yourself by centralizing PropTypes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjBw8m5BiLqjW9BHfmySfg.jpeg" /><figcaption><a href="https://unsplash.com/photos/Y5VHEKzHeLg">G</a>rand Central Station, New York, NY</figcaption></figure><p>There are three popular ways to handle types in React: <a href="https://reactjs.org/docs/typechecking-with-proptypes.html">PropTypes</a>, <a href="http://typescriptlang.org">TypeScript</a> and <a href="http://flowtype.org/">Flow</a>. This post is about PropTypes, which are currently the most popular.</p><h3>Cory House 🏠 on Twitter</h3><p>📊 For enforcing types in React, I typically use... #react RT&#39;s appreciated</p><p>Since PropTypes provide type warnings at runtime, it’s helpful to be as specific as possible.</p><ul><li>Component accepts an object? Declare the object’s shape.</li><li>Prop only accepts a specific list of values? Use oneOf.</li><li>Array should contain numbers? Use arrayOf.</li><li>You can even declare your own types. <a href="https://github.com/airbnb/prop-types">AirBnB offers many additional PropTypes</a>.</li></ul><p>Here’s a PropType example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e019278c6f44de68391613cd427f60bf/href">https://medium.com/media/e019278c6f44de68391613cd427f60bf/href</a></iframe><p>In real apps with large objects, this quickly leads to a lot of code. That’s a problem, because <strong>in React, you’ll often pass the same object to multiple components</strong>. Repeating these details in multiple component files breaks the <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principle</a> (don’t repeat yourself). Repeating yourself creates a maintenance problem.</p><p>The solution? <strong>Centralize your PropTypes</strong>.</p><h4>Here’s How to Centralize PropTypes</h4><p>I prefer centralizing PropTypes in /types/index.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f8c95bf8547914ded554ae773b5c67d/href">https://medium.com/media/7f8c95bf8547914ded554ae773b5c67d/href</a></iframe><p>I’m using named imports on line 2 to shorten the declarations. 👍</p><p>And here’s how I use the PropType I declared above:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d25d344201d77c812adc57179733deae/href">https://medium.com/media/d25d344201d77c812adc57179733deae/href</a></iframe><p>I use a named import to get a reference to the exported PropType declaration on line 2. And I put it to use on line 13.</p><p><strong>Benefits</strong>:</p><ol><li>The centralized PropType radically simplifies the component’s PropType declaration. Line 13 just references the centralized PropType, so it’s easy to read.</li><li>The centralized type only declares the shape, so you can still mark the prop as required as needed.</li><li>No more copy/paste. If the object shape changes later, you have a single place to update. 🎉</li></ol><p>Here’s a <a href="https://codesandbox.io/s/3vw24xnlqm">working example on CodeSandbox</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F3vw24xnlqm%3Fmodule%3D%252FUserDetails.js%26view%3Deditor&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F3vw24xnlqm%3Fmodule%3D%252FUserDetails.js%26view%3Deditor&amp;image=https%3A%2F%2Fcodesandbox.io%2Fstatic%2Fimg%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3048fa80cab9fa3dbbfde4ebdaef4c4/href">https://medium.com/media/b3048fa80cab9fa3dbbfde4ebdaef4c4/href</a></iframe><h4>Extra Credit: Generate Your PropTypes</h4><p>Finally, consider writing some custom code to generate your PropType declarations from your server-side code. For example, if your API is written using a strongly typed language like C# or Java, consider generating your PropType declarations as part of your server-side API build process by reading the shape of your server-side classes. This way you don’t have to worry about keeping your client-side PropTypes and your server-side API code in sync. 👍</p><p><strong>Side-note</strong>: If you know of a project that does this for any server-side languages, please reply in the comments and I’ll add a link here.</p><p><strong>Edit</strong>: You can convert JSON into PropTypes using <a href="https://transform.now.sh/">transform.now.sh</a>. 🎉</p><h3>Summary</h3><ol><li>Declare your PropTypes as explicitly as possible, so you know when you’ve made a mistake.</li><li>Centralize your PropTypes to avoid repeating yourself.</li><li>If you’re working in a strongly typed language on the server, consider generating your PropTypes by reading your server-side code. This assures your PropTypes match your server-side types.</li></ol><h3>Looking for More on React? ⚛️</h3><p>I’ve authored <a href="http://bit.ly/psauthorpageimmutablepost">multiple React and JavaScript courses</a> on Pluralsight (<a href="http://bit.ly/pstrialimmutablepost">free trial</a>).</p><figure><a href="https://www.pluralsight.com/authors/cory-house"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*BkPc3o2d2bz0YEO7z5C2JQ.png" /></a></figure><p><a href="https://twitter.com/housecor">Cory House</a> is the author of <a href="http://pluralsight.com/author/cory-house">multiple courses on JavaScript, React, clean code, .NET, and more on Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect at VinSolutions, a Microsoft MVP, and trains software developers internationally on software practices like front-end development and clean coding. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f981ff672f3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7 Reasons to Outlaw React’s Functional Components]]></title>
            <link>https://medium.com/@housecor/7-reasons-to-outlaw-reacts-functional-components-ff5b5ae09b7c?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff5b5ae09b7c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Tue, 10 Oct 2017 14:07:29 GMT</pubDate>
            <atom:updated>2019-06-19T23:37:53.236Z</atom:updated>
            <content:encoded><![CDATA[<h4>Are React’s Functional Components Worth The Cost?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nywxB5PdmQq8zmB_TnMTbQ.jpeg" /><figcaption>Stop, collaborate, and listen.</figcaption></figure><p><strong>Update 5/31/19</strong>: React 16.8 added <a href="https://reactjs.org/docs/hooks-intro.html">Hooks</a>, which mean you can use functional components for nearly everything! 🎉 Function components are the future of React. So bottom-line, use functional components for future development. That said, the tradeoffs below apply for older codebases where Hooks aren’t an option. Happy coding!</p><p>I’m spending the week consulting a team in Seattle to help <a href="http://reactjsconsulting.com">accelerate their transition to React</a>. Today, we discussed the <a href="https://medium.freecodecamp.org/8-key-react-component-decisions-cc965db11594">8 key decisions to make to standardize React development</a>.</p><p>I shared <a href="https://hackernoon.com/react-stateless-functional-components-nine-wins-you-might-have-overlooked-997b0d933dbc">9 reasons I’m a fan of functional components</a>. One response surprised me:</p><blockquote>“Let’s forbid using functional components.”</blockquote><p>Woah, really? We discussed the issue at length. Here’s why.</p><h4>1. Conversion Hassle</h4><p>Functional components don’t support state, refs, or lifecycle methods. They can’t extend PureComponent either. Sometimes, you’ll create a functional component only to realize that you need one of these class-only features later. In these situations, it’s a hassle to manually convert to a function into a class.</p><p><strong>Edit</strong>: Instead of converting to a class, you can enhance existing functional with lifecycle methods, state, and more via <a href="https://github.com/acdlite/recompose">recompose</a>.</p><h4>2. Messy Diffs</h4><p>After you’ve finished the conversion, the diff is noisy. Even a trivial one-line change results in a multi-line code review.</p><p>Here’s an example of converting a functional component to a class so that it can be declared a PureComponent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4LLOPCNJLPf2mqndgH6Jg.png" /></figure><p>If this component were declared as a class from the start, the true intent of the commit would be crystal clear — it would require a 4 character change:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udhxm4DiyVhJucx_aCh8Gg.png" /></figure><p>Conversion obscures the component’s history by creating the illusion that the component has been largely rewritten when in fact you may have made a very trivial change. The person who does the conversion will be “blamed” for writing many lines that they merely changed for conversion reasons.</p><h4>3. Minor Signal to Noise Differences</h4><p>Compare a minimal class to a function, and the differences are minor. Remember, constructors are optional without state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RBAZms126DhaLb-ymPkkJg.png" /><figcaption>A class without default props is only 3 lines longer (due to explicit render and destructuring on separate line). Without destructuring a class is only 2 lines longer.</figcaption></figure><p><strong>Correction</strong>: Oops! I forgot the functional style can be a one-liner with a simple arrow function:</p><pre>const Hello = ({greeting, firstName}) =&gt; &lt;div&gt;{greeting} {firstName}&lt;/div&gt;</pre><h4>4. Inconsistency</h4><p>Function and class components look different. This inconsistency can slow developers down as they shift between the two styles.</p><ul><li>In classes, you say <strong>this.props</strong>, in functions, you say <strong>props</strong>.</li><li>In classes, you declare a render<strong> </strong>function. In functions, you don’t.</li><li>In classes, you destructure at the top of render. In functions, you destructure in the function’s argument list.</li><li>In classes, you declare default props below the component (or via class properties if you’re willing to use a <a href="https://tc39.github.io/proposal-class-fields/">stage-3 feature</a>). In functions, you declare default props using default arguments.</li></ul><p>These subtle differences add friction for new devs, and the context switching leads to mistakes for experienced devs too.</p><h4>5. Classes Are Familiar to OO Developers</h4><p>Yes, JavaScript’s classes are certainly different than Java and C# classes. But anyone working in OO-land on the server is likely to find this simple rule easy to understand:</p><blockquote>“A React component is a class that extends React.Component.”</blockquote><p>Adding a nuanced conversation about how and when to use plain functions adds confusion for OO devs who are already accustomed to being required to use classes for everything. Now I’m not saying this mindset is healthy — the React community fosters more of a functional mindset. But, one must acknowledge that functional components create mental-model friction for OO devs.</p><h4>6. No Performance Benefits, Yet</h4><p>While the React team has alluded to the chance that functional components will be faster or more efficient in the future, that’s not the case yet. So one could argue functional components are currently a premature optimization.</p><p>And since functional components require conversion to a class to implement today’s performance tweaks like shouldComponentUpdate and PureComponent, they’re actually more of a hassle to optimize for performance today.</p><p><strong>Update</strong>: With React 16.6+, you can declare “pure” functional components via <a href="https://reactjs.org/docs/react-api.html#reactmemo">React.memo</a>.</p><h4>7. Yet another decision</h4><p>Finally, JavaScript developers already have a <a href="https://medium.freecodecamp.org/you-need-a-javascript-starter-kit-ff12d90ed8c5">ridiculous number of decisions to make</a>. Banning functional components eliminates a decision: Always create a class.</p><h3>Summary</h3><p><a href="https://medium.freecodecamp.org/8-key-react-component-decisions-cc965db11594">I’m still a fan of functional components</a>. But now I recognize they’re not necessarily a slam dunk for everyone. So, as usual, consider the tradeoffs. 👍</p><p>See other downsides or benefits? Chime in below.</p><h3>Looking for More on React? ⚛️</h3><p>I’ve authored <a href="http://bit.ly/psauthorpageimmutablepost">multiple React and JavaScript courses</a> on Pluralsight (<a href="http://bit.ly/pstrialimmutablepost">free trial</a>).</p><figure><a href="https://www.pluralsight.com/authors/cory-house"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*BkPc3o2d2bz0YEO7z5C2JQ.png" /></a></figure><p><a href="https://twitter.com/housecor">Cory House</a> is the author of <a href="http://pluralsight.com/author/cory-house">multiple courses on JavaScript, React, clean code, .NET, and more on Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect at VinSolutions, a Microsoft MVP, and trains software developers internationally on software practices like front-end development and clean coding. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff5b5ae09b7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[8 Key React Component Decisions]]></title>
            <link>https://medium.com/@housecor/8-key-react-component-decisions-cc965db11594?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc965db11594</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Mon, 02 Oct 2017 13:20:17 GMT</pubDate>
            <atom:updated>2019-06-19T23:38:42.905Z</atom:updated>
            <content:encoded><![CDATA[<h4>Standardize your React development with these key decisions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XgHYXVXoyziBKd7Or5IliQ.jpeg" /><figcaption>With this many options, choosing is hard.</figcaption></figure><p>React was open-sourced in 2013. Since then, it has evolved. As you search the web, you’ll stumble across old posts with dated approaches. So, here are eight key decisions your team needs to make when writing React components today.</p><h3>Decision 1: Dev Environment</h3><p>Before you write your first component, your team needs to agree on a dev environment. Lots of options…</p><h3>Cory House 🏠 on Twitter</h3><p>📊Poll: What boilerplate do you typically use for React development today? #react #reactjs</p><p>Sure, you can <a href="https://www.pluralsight.com/courses/javascript-development-environment">build a JS dev environment from scratch</a>. 25% of React devs do just that. My current team uses a fork of create-react-app with additional features such as a <a href="https://medium.freecodecamp.org/rapid-development-via-mock-apis-e559087be066">realistic mock API that supports CRUD</a>, a <a href="https://www.pluralsight.com/courses/react-creating-reusable-components">reusable component library</a>, and linting enhancements (we lint our test files too, which create-react-app ignores). I enjoy create-react-app, but <a href="http://andrewhfarmer.com/starter-project/">this tool will help you compare many compelling alternatives</a>. Want to render on the server? Check out <a href="http://gatsbyjs.org">Gatsby</a> or <a href="https://github.com/zeit/next.js/">Next.js</a>. You can even consider using an online editor like <a href="https://codesandbox.io">CodeSandbox</a>.</p><h3>Decision 2: Types</h3><p>You can ignore types, use <a href="https://reactjs.org/docs/typechecking-with-proptypes.html">prop-types</a>, use <a href="https://flow.org">Flow</a>, or use <a href="https://www.typescriptlang.org">TypeScript</a>. Note that prop-types was extracted to a <a href="https://www.npmjs.com/package/prop-types">separate library</a> in React 15.5, so older posts will show imports that don’t work anymore.</p><p>The community remains divided on this topic:</p><h3>Cory House 🏠 on Twitter</h3><p>📊 For enforcing types in React, I typically use... #react RT&#39;s appreciated</p><p>I prefer prop-types because I find it provides sufficient type safety in React components with little friction. Using the combination of Babel, <a href="https://facebook.github.io/jest/">Jest tests</a>, <a href="http://www.eslint.org">ESLint</a>, and prop-types, I rarely see runtime type issues.</p><h3>Decision 3: createClass vs ES Class</h3><p>React.createClass was the original API, but in 15.5, it was deprecated. Some feel <a href="https://medium.com/dailyjs/we-jumped-the-gun-moving-react-components-to-es2015-class-syntax-2b2bb6f35cb3">we jumped the gun moving to ES classes</a>. Regardless, the createClass style has been moved out of React core and <a href="https://reactjs.org/docs/react-without-es6.html">relegated to a single page called “React without ES6” in the React docs</a>. So it’s clear: ES classes are the future. You can easily convert from createClass to ES Classes using <a href="https://github.com/reactjs/react-codemod">react-codemod</a>.</p><h3>Decision 4: Class vs Functional</h3><p>You can declare React components via a class or a function. Classes are useful when you need refs, and lifecycle methods. Here are <a href="https://hackernoon.com/react-stateless-functional-components-nine-wins-you-might-have-overlooked-997b0d933dbc">9 reasons to consider using functions when possible</a>. But it’s also worth noting that <a href="https://medium.freecodecamp.org/7-reasons-to-outlaw-reacts-functional-components-ff5b5ae09b7c">there are some downsides to functional components</a>.</p><h3>Decision 5: State</h3><p>You can use plain React component state. It’s sufficient. <a href="https://reactjs.org/docs/lifting-state-up.html">Lifting state</a> scales nicely. Or, you may enjoy Redux or MobX:</p><h3>Adam Rackis on Twitter</h3><p>No flame wars please - honestly curious where the React community is these days. For new Pr/React projects, I use ___ for state management.</p><p><a href="https://www.pluralsight.com/courses/react-redux-react-router-es6">I’m a fan of Redux</a>, but I often use plain React since it’s simpler. In my current role, we’ve shipped about a dozen React apps, and decided Redux was worth it for two. I prefer shipping many, small, autonomous apps over a single large app.</p><p>On a related note, if you’re interested in immutable state, there are at least <a href="https://medium.com/@housecor/handling-state-in-react-four-immutable-approaches-to-consider-d1f5c00249d5">4 ways to keep your state immutable</a>.</p><h3>Decision 6: Binding</h3><p>There are at least <a href="https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56">half a dozen ways you can handle binding</a> in React components. In React’s defense, this is mostly because modern JS offers many ways to handle binding. You can bind in the constructor, bind in render, use an arrow function in render, use a class property, or use decorators. <a href="https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56">See the comments on this post</a> for even more options! Each approach has its merits, but assuming you’re comfortable with experimental features,<a href="https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56"> I suggest using class properties (aka property initializers) by default today</a>.</p><p>This poll is from Aug 2016. Since then, it appears class properties have grown in popularity, and createClass has reduced in popularity.</p><h3>Cory House 🏠 on Twitter</h3><p>How do you handle binding in #reactjs today? Examples: https://t.co/z7OKxe39VA</p><p><strong>Side note</strong>: Many are confused about why arrow functions and bind in render are potentially problematic. The real reason? <a href="https://medium.freecodecamp.org/why-arrow-functions-and-bind-in-reacts-render-are-problematic-f1c08b060e36">It makes shouldComponentUpdate and PureComponent cranky</a>.</p><h3>Decision 7: Styling</h3><p>Here’s where the options get seriously intense. There are 50+ ways to style your components including React’s inline styles, traditional CSS, Sass/Less, <a href="https://github.com/css-modules/css-modules">CSS Modules</a>, and <a href="https://github.com/MicheleBertoli/css-in-js">56 CSS-in-JS options</a>. Not kidding. I explore React styling approaches in detail <a href="https://www.pluralsight.com/courses/react-creating-reusable-components">in the styling module of this course</a>, but here’s the summary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Q3FXqxI6akM-GWV2rqlcw.png" /><figcaption>Red is bad. Green is good. Gray is warning.</figcaption></figure><p>See why there is so much fragmentation in React’s styling options? There’s no clear winner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_K-z-ZfTXNFwyedAXrS5sA.png" /><figcaption>Looks like CSS-in-JS is gaining steam. CSS modules is losing steam.</figcaption></figure><p>My current team uses Sass with BEM and are happy enough, but I also enjoy <a href="https://www.styled-components.com">styled-components</a>.</p><h3>Decision 8: Reusable Logic</h3><p>React initially embraced <a href="https://reactjs.org/docs/react-without-es6.html#mixins">mixins</a> as a mechanism for sharing code between components. But mixins caused issues and are <a href="https://reactjs.org/blog/2016/07/13/mixins-considered-harmful.html">now considered harmful</a>. You can’t use mixins with ES class components, so now people <a href="https://reactjs.org/docs/higher-order-components.html">utilize higher-order components</a> and <a href="https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce">render props</a> (aka function as child) to share code between components.</p><h3>Kent C. Dodds on Twitter</h3><p>POLL for devs writing #ReactJS]: Which do you prefer? HOC: https://t.co/aczxcPUd8j Render Props: https://t.co/2haYUuGK7z</p><p>Higher-order components are currently more popular, but I prefer render props since they’re often easier to read and create. <a href="https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce">Michael Jackson recently sold me with this</a>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBcVAq3YFiuc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBcVAq3YFiuc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBcVAq3YFiuc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a593086aef40326eba135e5931fe3917/href">https://medium.com/media/a593086aef40326eba135e5931fe3917/href</a></iframe><h3>And that’s not all…</h3><p>There are more decisions:</p><ul><li>Will you use a <a href="https://github.com/facebookincubator/create-react-app/issues/87#issuecomment-234627904">.js or .jsx extension</a>?</li><li>Will you place <a href="https://medium.com/styled-components/component-folder-pattern-ee42df37ec68">each component in its own folder</a>?</li><li>Will you enforce one component per file? Will you <a href="https://hackernoon.com/the-100-correct-way-to-structure-a-react-app-or-why-theres-no-such-thing-3ede534ef1ed">drive people nuts by slapping an index.js file in each directory</a>?</li><li>If you use propTypes, will you declare them at the bottom, or within the class itself using <a href="https://michalzalecki.com/react-components-and-class-properties/#static-fields">static properties</a>? Will you <a href="https://medium.freecodecamp.org/react-pattern-centralized-proptypes-f981ff672f3b">centralize your PropTypes</a>? Will you <a href="https://iamakulov.com/notes/deep-proptypes/?utm_content=buffer57abf&amp;utm_medium=social&amp;utm_source=twitter.com&amp;utm_campaign=buffer">declare propTypes as deeply as possible</a>?</li><li>Will you initialize state traditionally in the constructor or utilize the <a href="http://stackoverflow.com/questions/35662932/react-constructor-es6-vs-es7">property initializer syntax</a>?</li></ul><p>And since React is mostly just JavaScript, you have the usual long list of JS development style decisions such as <a href="https://eslint.org/docs/rules/semi">semicolons</a>, <a href="https://eslint.org/docs/rules/comma-dangle">trailing commas</a>, <a href="https://github.com/prettier/prettier">formatting</a>, and <a href="https://jaketrent.com/post/naming-event-handlers-react/">event handler naming</a> to consider too.</p><h3>Choose a Standard, Then Automate Enforcement</h3><p>And all this up, and there are dozens of combinations you may see in the wild today.</p><p>So, these next steps are key:</p><blockquote>1. Discuss these decisions as a team and document your standard.</blockquote><blockquote>2. Don’t waste time manually policing inconsistency in code reviews. Enforce your standards using tools like <a href="https://eslint.org">ESLint</a>, <a href="https://github.com/yannickcr/eslint-plugin-react">eslint-plugin-react</a>, and <a href="https://github.com/prettier/prettier">prettier</a>.</blockquote><blockquote>3. Need to restructure existing React components? Use <a href="https://github.com/reactjs/react-codemod">react-codemod</a> to automate the process.</blockquote><p>Other key decisions I’ve overlooked? Chime in via the comments.</p><h3>Looking for More on React? ⚛️</h3><p>I’ve authored <a href="http://bit.ly/psauthorpageimmutablepost">multiple React and JavaScript courses</a> on Pluralsight (<a href="http://bit.ly/pstrialimmutablepost">free trial</a>).</p><figure><a href="https://www.pluralsight.com/authors/cory-house"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*BkPc3o2d2bz0YEO7z5C2JQ.png" /></a></figure><p><a href="https://twitter.com/housecor">Cory House</a> is the author of <a href="http://pluralsight.com/author/cory-house">multiple courses on JavaScript, React, clean code, .NET, and more on Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect at VinSolutions, a Microsoft MVP, and trains software developers internationally on software practices like front-end development and clean coding. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc965db11594" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reusable Web Application Strategies: three patterns for running the same app in multiple spots]]></title>
            <link>https://medium.com/@housecor/reusable-web-application-strategies-d51517ea68c8?source=rss-e986f7cdb458------2</link>
            <guid isPermaLink="false">https://medium.com/p/d51517ea68c8</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Cory House]]></dc:creator>
            <pubDate>Mon, 25 Sep 2017 19:44:20 GMT</pubDate>
            <atom:updated>2017-09-30T22:19:23.476Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reusable Web Application Strategies</h3><h4>Three patterns for running the same app in multiple spots</h4><p>Imagine your team just deployed an amazing todo list app. A month later, another team in your company wants to run your todo app within their invoice app.</p><p>So now you need to run your todo app in two spots:</p><ol><li>By itself</li><li>Embedded within the invoice app</li></ol><p>What’s the best way to handle that? 🤔</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uyfg5ldLO2nfH7wZqJnfw.png" /></figure><p>To run an app in multiple spots, you have three options:</p><ol><li><strong>iframe</strong> — Embed the todo app in the invoice app via an &lt;iframe&gt;.</li><li><strong>Reusable App Component</strong> — Share the entire todo app.</li><li><strong>Reusable UI Component</strong> — Share only the todo app’s markup.</li></ol><p>Option 2 and 3 are typically shared via npm for client-side apps.</p><p>In a hurry? Here’s the summary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZKpc-2SNREdC-t9hSBWw6Q.png" /><figcaption>Green is good. Red is bad. Orange is warning.</figcaption></figure><p>Let’s explore the merits of each approach.</p><h3>Option 1: iFrame</h3><p>With an iframe, you can compose two apps together by placing the “child” app in an iframe. So in our example, the invoice app would embed the todo app via an iframe. Easy. But not so fast…</p><h4>When is an iframe a good fit?</h4><ol><li><strong>Incompatible tech</strong> — If the apps you’re composing use incompatible technologies, this is your only option. For example, if one app is built in Ruby and the other in ASP.NET, an iframe allows the two apps to display side-by-side, even though they are actually incompatible and hosted separately.</li><li><strong>Small, static dimensions -</strong> The app you’re framing in has a static height and width. Dynamically resizing iframes is doable, but adds complexity.</li><li><strong>Common authentication story -</strong> An iframed app shouldn’t require separate authentication. Separate authentication can lead to clunky interactions as the framed app may prompt for separate credentials or timeout at a different time than the hosting app.</li><li><strong>Runs the same way everywhere</strong> — With an iframe, the framed app will run the same way in each spot where it’s framed in. If you need significantly different behavior in different contexts, see the other approaches below.</li><li><strong>No common data</strong> — With an iframe, the composed applications should avoid displaying the same data. Framing an app can lead to duplicate, wasteful API calls and out-of-sync issues between the framed app and its parent. Data changes in the iframe must be carefully communicated to the parent and vice-versa, or the user will see out-of-sync data.</li><li><strong>Few inter-app interactions</strong> — There should be very few interactions between the hosting app and the iframed app. Sure, you can use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage">window.postMessage</a> to pass messages between the iframe and the hosting app, but this approach should be used sparingly since it’s brittle.</li><li><strong>A single team supports both apps </strong>— With iframes, the same team should ideally own and maintain both the parent app and the framed app. If not, you must accept an ongoing coordination relationship between the teams that support the applications to assure they remain compatible. Separate teams create an ongoing risk and maintenance burden to maintain a successful and stable integration.</li><li><strong>Only need to do this once</strong> — Due to the point above, you should only iframe an app once to avoid creating a significant maintenance burden. The more times an app is framed, the more places you risk breaking when you make changes.</li><li><strong>Comfortable with deployment risks</strong> — With an iframe, you must accept the risk that a production deploy of the framed application may impact the parent app at any time. This is another reason having the same team support both the parent and framed app is useful.</li></ol><h3>Option 2: Share App Component</h3><p>Node’s package manager, npm, has become the defacto way to share JavaScript. With this approach, you create an npm package and place the completed application inside. And it need not be public — you can create a private npm package on npm too.</p><p>The process for creating a reusable component library is beyond the scope of this post. I explore how to build your own reusable component library in “<a href="https://app.pluralsight.com/library/courses/react-creating-reusable-components">Building Reusable React Components</a>”.</p><p>Since you’re sharing the entire app, it may include API calls, authentication concerns, and data flow concerns like Flux/Redux, etc. This is a highly opinionated piece of code.</p><h4>When is the reusable app component approach a good fit?</h4><ol><li><strong>Compatible tech — </strong>Since you’re sharing a reusable component, the parent app needs to be compatible. For instance, if you’re sharing a React component, the parent app should ideally be written in React too.</li><li><strong>Dynamic size </strong>— This approach is useful if your app’s width/height are dynamic so it doesn’t fit well in a statically sized frame.</li><li><strong>Common authentication story </strong>— The two applications should ideally utilize the same authentication. Separate authentication can lead to clunky interactions as each app may prompt for separate credentials or timeout at a different time.</li><li><strong>You want the app to run the same way everywhere</strong> — Since API, authentication, and state management are built in, the app will operate the same way everywhere.</li><li><strong>No common data</strong> — The two applications mostly work with separate data. Displaying apps side-by-side can lead to duplicate, wasteful API calls as each app makes requests for the same data. It can also lead to out-of-sync issues between the two apps. Data changes in one must be carefully communicated to the other, or the user will see out-of-sync data between the two apps.</li><li><strong>Few inter-app interactions</strong> — There should be few interactions between the two apps. Sure, you can use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage">window.postMessage</a> to pass messages between them, but this approach should be used sparingly since it’s brittle.</li><li><strong>A single team supports both apps </strong>— With this approach, ideally the same team owns and maintains both apps. If not, you must be willing to accept an ongoing coordination relationship between the teams that support the two applications to assure they remain compatible. Separate teams create an ongoing risk and maintenance burden to maintain a successful and stable integration.</li></ol><h3>Option 3: Share UI Component</h3><p>This option is similar to option #2 above, except you <strong>share only the markup</strong>. With this approach, you omit authentication, API calls, and state management so that <strong>the component is basically just reusable HTML</strong>.</p><p>Popular examples of simple components like this include <a href="http://www.material-ui.com/#/">Material-UI</a> and <a href="https://react-bootstrap.github.io">React Bootstrap</a>. Of course, a reusable app component has more moving parts, but it operates on the same idea.</p><p>Before we discuss the merits of this approach, let me address a common question: “Should my reusable components embed API calls and auth?”</p><p>My take? <strong>Avoid embedding API, auth, and state management concerns in reusable components.</strong></p><p>Here’s why:</p><ol><li>It limits reuse by tying the front-end to a specific API, auth, state management story.</li><li>Often, separate developers/teams manage the UI and API. Embedding API calls in a reusable component couples the UI team and the API team together. If one side changes, it impacts the other, which creates an ongoing coordination overhead and maintenance burden.</li></ol><p>But yes, this does mean each time someone uses your reusable component, they have to wire up the API calls and pass them in on props.</p><h4>When is the reusable UI component approach a good fit?</h4><ol><li><strong>Compatible tech — </strong>Since you’re sharing a reusable component, the parent app needs to be compatible. For instance, if you’re sharing a React component, the parent app should be written in React too.</li><li><strong>Dynamic size </strong>— This approach is useful if your app’s width/height are dynamic so it doesn’t fit well in a statically sized frame.</li><li><strong>Different authentication stories</strong> — Since this approach is basically just reusable HTML, the apps you want to compose can have different auth stories, or the auth story can differ in each place the component is used.</li><li><strong>Different behaviors in each use case</strong> — With this approach, you can reuse a front-end, but call different APIs in each use case. Each copy of the front-end can operate completely differently. You can set different props and hit different APIs in each use case to tailor behavior as needed.</li><li><strong>Common data</strong> — With this approach, the UI you’re composing can utilize and display the parent app’s data. It’s a single, cohesive app. This avoids duplicate API calls and out-of-sync issues, saves bandwidth, and improves performance.</li><li><strong>Many cross-app interactions</strong> — If there are significant interactions and shared data between the applications, this approach assures that the two applications feel like a single cohesive experience…because <strong><em>this approach creates a single, cohesive app</em></strong>.</li><li><strong>Discoverability is desirable</strong> — You want to publicize the existence of a rich, reusable front-end as a component. You can place this component in your reusable component library and document the props it accepts so that others can easily find and reuse it in different contexts.</li><li><strong>Multiple use cases</strong>— You plan to deploy this front end in many places. This approach is more flexible than the other approaches since you’re just sharing a highly configurable front-end.</li><li><strong>Separate UI and API teams</strong> — If you have a separate UI team, tying the UI to the API via the other approaches is unattractive due to the aformentioned coordination overhead. With this approach, you control when to update the npm package. You can deploy a new version of the reusable front end when desired, on a per app basis.</li></ol><h3>Summary</h3><p>As usual, context is king. In most cases, I recommend approach #3, but each has valid use cases. Have another way to handle this? Please chime in via the comments.</p><p><a href="https://twitter.com/housecor">Cory House</a> is the author of <a href="http://pluralsight.com/author/cory-house">multiple courses on JavaScript, React, clean code, .NET, and more on Pluralsight</a>. He is principal consultant at <a href="http://www.reactjsconsulting.com">reactjsconsulting.com</a>, a Software Architect at VinSolutions, a Microsoft MVP, and trains software developers internationally on software practices like front-end development and clean coding. Cory tweets about JavaScript and front-end development on Twitter as <a href="http://www.twitter.com/housecor">@housecor</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d51517ea68c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>