<?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 Richard Moss on Medium]]></title>
        <description><![CDATA[Stories by Richard Moss on Medium]]></description>
        <link>https://medium.com/@richard_13764?source=rss-3d90c9462fe5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gA4JDDp8jklfHia1.</url>
            <title>Stories by Richard Moss on Medium</title>
            <link>https://medium.com/@richard_13764?source=rss-3d90c9462fe5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:21:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@richard_13764/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[Heading to React Amsterdam? We’ll see you there!]]></title>
            <link>https://medium.com/@richard_13764/heading-to-react-amsterdam-well-see-you-there-8c0e08976dec?source=rss-3d90c9462fe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c0e08976dec</guid>
            <category><![CDATA[react-amsterdam]]></category>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Richard Moss]]></dc:creator>
            <pubDate>Mon, 11 Feb 2019 11:00:04 GMT</pubDate>
            <atom:updated>2019-02-11T11:04:54.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUwQhNfzRMgTFlhMq_3mKg.jpeg" /></figure><p>As the alumni from our courses will probably tell you, we live and breathe all things React here at ReactJS Academy. True as that is, for some reason we’ve never had the opportunity to visit React Amsterdam before, the biggest React conference in the world!</p><p>This year, we’re going to set that right. We’re not just attending React Amsterdam though, we’re running a day-long React Amsterdam workshop, too. But the good news doesn’t stop there: before the conference, we’re also bringing our part-time course to Amsterdam in March. We don’t like to do things by half…</p><h3>Why React Amsterdam?</h3><p>If you haven’t heard of <a href="https://react.amsterdam/">React Amsterdam</a> before, you’ve been missing out. It’s the world’s largest conference dedicated to our favourite JavaScript library, with over 1300 React devs and fans convening for four days to learn, network and talk all things React.</p><p>React Amsterdam attracts the best and brightest minds working with React today. Expect speakers from industry giants like PayPal, Facebook, Amazon AWS, GitHub, Hive, and many more besides.</p><p>But that’s just on conference day itself. For the two days before the main conference starts, React devs can get extra training in workshops led by industry professionals and gurus.</p><p>In fact, we’re not only attending our first ever React Amsterdam conference this year. We’re also bringing a taster of our renowned ReactJS Academy training curriculum and teaching style. Join us on April 11th 2019 for the ReactJS Academy workshop!</p><h3>What to expect from our React Amsterdam workshop</h3><p>During our day-long <a href="https://react.amsterdam/workshops#react-native">React Amsterdam workshop</a>, you’ll get a taster of our reputed React knowledge and teaching approach.</p><p>Suitable for Intermediate JavaScript/React Developers and Junior React Native Developers, you’ll learn how to create reusable and maintainable React Native UI.</p><p>You’ll also understand the best practices and patterns for building real-world React Native applications.</p><p>Not bad for a day’s workshop, is it?</p><h3>Can’t wait until April? Join our Amsterdam part-time React course in March</h3><p>Here at ReactJS Academy, we’re all about helping developers take their career further by learning React. We were the first to start teaching React in Europe, and now we’re proud to bring our proactive, hands-on part-time courses to Amsterdam.</p><p>During the part-time React course, you will learn:</p><ul><li>Modern JavaScript</li><li>How to think in React</li><li>Routing &amp; data fetching</li><li>Forms &amp; auth</li><li>Styling in React</li><li>Redux &amp; Redux principles</li><li>Testing in JS</li><li>Advanced patterns</li></ul><p>Then in the final session, we’ll show you how to apply all you’ve learned to real-world projects, giving you the power to take your career even further.</p><p>See what our alumni thought of our training below:</p><p>Want to get involved in our part-time React courses in Amsterdam? <a href="https://reactjs.academy/react-redux-training-amsterdam/">Find out more and sign up today!</a></p><p>If you’re interested in attending React Amsterdam, better hurry: tickets are selling fast. <a href="https://www.eventbrite.com/e/react-amsterdam-conference-2019-tickets-51631771017">Reserve yours now</a>!</p><p><em>Originally published at </em><a href="https://reactjs.academy/blog/leanjs-react-amsterdam/"><em>reactjs.academy</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c0e08976dec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Google’s Cloud Functions and Realtime DB to write a server-less slack integration ]]></title>
            <link>https://medium.com/@richard_13764/using-googles-cloud-functions-and-realtime-db-to-write-a-server-less-slack-integration-53a83dcb583c?source=rss-3d90c9462fe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/53a83dcb583c</guid>
            <category><![CDATA[firebase-cloud-functions]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[google-cloud-functions]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[gatsbyjs]]></category>
            <dc:creator><![CDATA[Richard Moss]]></dc:creator>
            <pubDate>Thu, 04 Oct 2018 16:49:08 GMT</pubDate>
            <atom:updated>2018-10-04T16:51:24.728Z</atom:updated>
            <content:encoded><![CDATA[<ul><li><em>This article assumes a basic understanding of Firebase, it’s features and GUI console, CLI, and project setup. If you’re not familiar, check out the firebase docs to get started: </em><a href="https://firebase.google.com/docs/web/setup">https://firebase.google.com/docs/web/setup</a></li><li><em>It also assumes basic React, if you’re new to React I recommend </em><a href="https://medium.com/leanjs/introduction-to-react-3000e9cbcd26"><em>starting here</em></a></li></ul><h4><strong>The problem being solved</strong></h4><p>You have a nice new static website using Gatsby.js (or similar), which is mostly content based but you’d like people to be able to submit a basic contact form and receive the messages so you can respond 🤔. Doesn’t sound too hard, but then you realize you need to set up a backend or some kind of mail service or third party integration into your site to achieve this, costly in time, and maybe money.</p><h4>Enter Google Firebase and friends</h4><p>Turns out there is a simple, reliable and quick way to solve this problem while saving all the data and getting alerted to your messages quickly, I’ll run you through the steps:</p><p>If you don’t already use Firebase, head over to <a href="https://firebase.google.com/">https://firebase.google.com/</a> to get setup and install the cli tool with npm install -g firebase-tools</p><pre>npm install -g firebase-tools</pre><p>You’ll need to set up a config file in your project so it is connected to firebase using you api key etc. I recommend saving it in a folder as Firebase.js and exporting that</p><p>Now, you’ll need a basic contact form you want to hook up, maybe it looks something like this (In your React component):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*h5TzSv_P4Q2KUUbSm8dcNg.png" /></figure><h3>Setting up the realtime DB</h3><p>Our cloud function is going to trigger based on an update to the firebase realtime database, so the first thing we’ll need to do is save our form data there. In order to do so we can write a simple function to write to our DB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*DosYuuyPMhxhpTy624-e_g.png" /></figure><p>Just In case you were wondering, we are simply importing the db object here that is exported from our config file where our we specify our API key, projectId, etc.</p><p>We can now use this function so that our messages get saved on submit inside our component by using our doCreateMessage()function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*45iGEcEatQjFIC8EJ0E9rA.png" /></figure><p>You can see our change handlers at the bottom of this screenshot, forms in react is another topic though which is covered in depth elsewhere ;-)</p><p>Now if your setup all went according to plan, you should be able to see those names and email messages popping up in your firebase console inside “contactSubmissions”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*fhEdnP2oaaTgAzXJ6Mr94Q.png" /></figure><h3>Creating our Cloud Function</h3><p>So now we have a form that’s hooked up to our realtime DB 😁, we would like to get notified of when someone submits us a message. Here we can use a cloud function that simply listens for changes to our database and is invoked when one occurs.</p><p>When you set up firebase with the firebase init command it will have created a functions folder for you with an index.js file where you should write your function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QlTLJN7N1VHAM66Y7LaBgA.png" /></figure><p>Let’s walk through whats going on here:</p><ol><li>We import the required dependencies (this is node so we can’t use the ES6 import)</li><li>The admin variable is what gives us access to our DB, you’ll need to make sure that is installed in your functions package.json</li><li>We call the initializeApp()and pass in our config.</li><li>On line 7 we declare our function and export it. The function has a callback listener on our firebase DB listening for an onWrite. On line 8 we specify the ref in our database to target, in our case we want the contactSubmissions/{name}</li><li>The onWrite() callback has two params, data and context. In our case snap is a dataSnapshot (hence the name) with both before and after fields. We are interested in the value of the data after the snapshot so can use snap.after.val() to access it in our function.</li></ol><p>The context parameter provides information about the function&#39;s execution which we are not concerned with here, but it’s worth reading up on in the <a href="https://firebase.google.com/docs/reference/js/">documentation</a>.</p><p>Armed with a way to see what the data looks like after the function has been called, we can execute another function inside the callback to notify us of the contents. In this case we are going to write a simple Slack integration that posts a message to a channel using <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*054EX5QlqIrgCvI9whcS1g.png" /></figure><p>On important thing to remember here is that although it won’t cost anything due to the very generous free allowance in cloud function calls, you’ll <strong>need to be on the “Blaze” pay as you go plan</strong> to call external API’s. You can checkout the details <a href="https://firebase.google.com/pricing/?authuser=0">here</a> and just upgrade from your dash:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qys7xt1iWl3_D8npszC0iw.png" /></figure><p>Now when someone submits a message we should get it showing up in our slack channel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*nRVUFAc0Hk7sp9dpavErBg.png" /></figure><p>At <a href="https://reactjs.academy/">ReactJS Academy</a> and <a href="https://leanjs.com/">LeanJS</a> we are big fans of Google Cloud Functions as in our opinion the developer experience is nicer than with AWS lambda. We are using the approach outlined here for the contact form on <a href="https://leanjs.com/">leanjs.com</a></p><p>As of July 24th Google Cloud Functions are out of Beta and in <a href="https://cloud.google.com/functions/docs/release-notes">initial release</a> meaning they are now 100% production ready, we’ve been tracking their performance for the last year and can safely say that’s true 😀</p><p>Have fun with Cloud Functions and let us know how you get on!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53a83dcb583c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Great (and not so great) Gatsbyjs]]></title>
            <link>https://medium.com/@richard_13764/the-great-and-not-so-great-gatsbyjs-788b5fb34e77?source=rss-3d90c9462fe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/788b5fb34e77</guid>
            <category><![CDATA[static-site]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[server-side-rendering]]></category>
            <dc:creator><![CDATA[Richard Moss]]></dc:creator>
            <pubDate>Fri, 31 Aug 2018 12:33:57 GMT</pubDate>
            <atom:updated>2018-08-31T13:35:08.563Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c6YLHydVDm8PBAjggWX-3A.jpeg" /><figcaption>“So we beat on, boats against the current, borne back ceaselessly into the past.” <br>― <strong>F. Scott Fitzgerald, The Great Gatsby</strong></figcaption></figure><p><a href="https://www.gatsbyjs.org/"><em>Gatsbyjs</em></a><em> is a great addition in the toolkit of React developers. Like every tool though, knowing when to reach for it is key. At </em><a href="https://leanjs.com/"><em>LeanJS</em></a><em> we’ve now used Gatsby on 3 projects since Jan 2018, two of which are currently in production and one that we had to shift over. We’d like to share our experiences and conclusions :-)</em></p><h3>The Challenge</h3><p>In early Jan we had a project where we needed to migrate a literary site from it’s original flat file system to have a custom UI to deliver a user experience that matched it’s prestige. We were passed a Wordpress instance with all the data which had been ported over 😐. Our standard stack is React with SSR, GraphQL and serverless back-end. Luckily, as graphQL is awesome you can simply wrap and existing restAPI (like wordpress has) and consume it via graphQL, an approach we’ve taken before, so we were confident in taking this approach.</p><h3>Using Gatsby with a big data set (v1)</h3><p>As Gatsby was just starting to come on the scene, we spun up a quick prototype using the <a href="https://www.gatsbyjs.org/packages/gatsby-source-wordpress/?=wordpress#gatsby-source-wordpress">gatsby-source-wordpress</a> plugin to see if it was a viable option. In our case we had ~9000 bits of content (posts) which was admittedly ambitious given that it’d been tested with 900. But hey presto it worked! So all the Gatsby goodness such as out of the box code splitting and lightning fast navigation between pages looked like it was in the bag. The build time was at about 5 minutes which seemed reasonable for a mostly static site which would not have to be re-built more than a couple of times per-week.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*IpOyhduE4j_cchDpjZIevA.png" /></figure><p>Having carried out a user research phase, we ran an initial rapid prototyping phase using <a href="https://react.semantic-ui.com/">SemanticUI react </a>component libary to build a clickable prototype. Up to this point everything was working well minus a couple of build errors from time to time.</p><h3>The big issues</h3><p>For those who have been working with Gatsby a bit, you’ll have noticed there is a big difference between when you are running something in “develop” and wether that works when you run a build. Put simply, <strong>just because you can run something locally using “gatsby develop”, that doesn’t mean it will build with no errors. </strong>Of course the solution to this is to run the build regularly and then use a basic local server to check everything.</p><p>Solving errors that occur during the build is not ideal, as if your team is making a lot of changes quickly and runs the build only a couple of times a week, it’s possible you have multiple errors to solve and you’ll need to re-build every time to see the error. When your build time is 5 minuets this is a minor annoyance, but what happened next was a bit more dramatic…</p><p>When you start to put in a lot of styling (via styled components) and use other open source library’s to add functionality, the build time will start to increase dramatically. In our case it went got up to about <strong>25 minutes</strong>. At this stage it’s no longer viable to keep running builds all the time and solving the errors becomes increasingly difficult. The second big problem is that due to the way the static build works, everything is stored in memory during the build so you need to have a large capacity of RAM to handle it. After a certain point (after more libs were added) everyones computer was running out of memory when trying to build the site.</p><pre>RangeError: Maximum call stack size exceeded</pre><p>This is now a fairly well known issue and you can read more on it in this <a href="https://github.com/gatsbyjs/gatsby/issues/3341">thread</a>. To save you some reading though, the answer is that it’s solved in V2 (still in Beta currently) as they are no longer using the same webpack static build process that was causing the issue.</p><p>Back in January however V2 was not really on the horizon and we needed to deliver on a tight timeline. What we did was take the decision to move the whole gatsby site over to a standard create-react-app with server-side rendering and use GraphQL to consume the wp data via <a href="https://github.com/wp-graphql/wp-graphql">wp-graphql</a>.</p><p>This was not the easiest thing to do, but in the end we got it over onto our standard stack in about 4 days 😅.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*HGwS3UoOwk2_UkPNxKbb2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*oHmdmsS6pIlFwI0vId0iiQ.png" /></figure><h3>The lesson learned</h3><p>The key learning from this experience was that when using a new tool, <strong>you need to be prepared and able to quickly adapt to your “default” stack.</strong></p><p>The React ecosystem is awesome and is very un-opinionated. This is great but it means that we need to be more prepared to make decisions as engineers and fully understand all the technologies that are working in conjunction. When you’re on a tight deadline, it’s easy to fall into the trap of wanting to go down the framework route, where <em>convention over configuration </em>will help you get the job done faster. <strong>However, when the flint strikes the metal, you need to be confident that you can make a rapid change and go more <em>vanilla. </em></strong>While<strong><em> </em></strong>Gatsby is a great tool, there is no doubt that it is more opinionated, with all of the advantages (and disadvantages) that come along with that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*q8-lnHAueczG_omMnWbbMg.png" /><figcaption>Our prototype homepage for the Agni Magazine</figcaption></figure><h3>Opinionated vs Vanilla</h3><p>You may have been thinking that the conclusion is to just always go as <em>vanilla</em> as possible. Modern software engineering must be more nuanced though if you want to achieve a good balance in speed and quality. At <a href="https://reactjs.academy/">ReactJS Academy</a> we are always pushing the point that you must be a good JavaScript dev if you want to be a good React dev. As <a href="https://twitter.com/getify">Kyle Simpson</a> once said to students at one of our bootcamps:</p><blockquote>“You should aim to be an expert in your layer of the stack, and have a very good working knowledge of the level below.”</blockquote><p>For us that means being expert in the React ecosystem and very high level at vanilla JS. Failing this, you can’t expect to fix things quickly when they go wrong, which ultimately could lead to a negative experience for everyone concerned. This was again highlighted during the switch over, without knowing how to implement SRR in React, we would have either continued to struggle on or delivered an inferior result. You can read up on how to do SSR in React with concise instructions here: <a href="https://github.com/leanjscom/fb-messenger/tree/SSR-part1#reactjs-facebook-messenger">https://github.com/leanjscom/fb-messenger/tree/SSR-part1#reactjs-facebook-messenger</a></p><h3>So when and where do we use Gatsby?</h3><p>Having this experience with Gatsby on a project was not something that put us off, if anything the opposite. The benefits are pretty clear. If you are a team that is well versed in rapidly building apps with React’s component based architecture, when faced with a content heavy static site, Gatsby is a great option. So when we decided it was time to re-vamp <a href="https://reactjs.academy/">ReactJS Academy</a> and <a href="https://leanjs.com/">LeanJS</a> websites (previously Jekyll), we knew where to turn. In both cases the sites are not complex, but by building with Gatsby we can integrate all our React experience and workflows in order to rapidly build and test the sites. When there is no big data set or tricky integration via a plugin, for React developers who want to build a presentational site such as a blog or CV, Gatsby is a great option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*Y62n3GjPuclMi-fAJ5sikg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*exsSkJBfwbqNYUfC7rBWvg.png" /></figure><h3>Conclusion</h3><p>Pick the right tool for the job. If you’re building a basic static site and you know and love React, Gatsby is my recommendation. But take the time to discuss it with your team, make sure you can also convince others of the benefits before charging ahead. If you are building a complex web app, the answer is more mixed, but think carefully about the tool you pick and wether it is appropriate. Not planning is planning for failure, so whatever you choose you need to be both confident with the underlying technology and have a contingency plan 😉.</p><p>Let us know your experiences with Gatsby and other tools in the React ecosystem in the comments 😎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=788b5fb34e77" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React 16 Error handling with componentDidCatch()]]></title>
            <link>https://medium.com/@richard_13764/react-16-error-handing-with-componentdidcatch-fa4e248d45d7?source=rss-3d90c9462fe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa4e248d45d7</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[error-handling]]></category>
            <dc:creator><![CDATA[Richard Moss]]></dc:creator>
            <pubDate>Thu, 28 Sep 2017 22:32:28 GMT</pubDate>
            <atom:updated>2017-10-07T15:09:04.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*VRF_UuVXLQL-N-vLt5fjpA.png" /></figure><p>React 16 is here, and with it comes new behavior for uncaught errors, a new lifecycle method, and the concept of “Error Boundaries”. Lets take each of these in turn.</p><h3><strong>Uncaught Errors unmount the whole component tree.</strong></h3><p>This means in practice that where previously the user would have seen some corrupted UI when there was an uncaught error, now they will simply see nothing. This may sound dramatic but it’s based on the logic that it’s <a href="https://facebook.github.io/react/blog/2017/07/26/error-handling-in-react-16.html">worse to leave corrupted UI in place than to completely remove it.</a></p><p>Lets look at a code example, <em>can you spot the error?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uqDUTtNer34qZTsCD13RrA.png" /></figure><p>So here when the user clicks on the “Update” button, we will get an Uncaught type error as it will try to read the property name on null. The big difference from earlier versions is that when this occurs in production, from the users perspective the whole UI will disappear, not an ideal UX!</p><h3>Handing errors with componentDidCatch()</h3><p>React 16 introduces this new lifecycle method which allows us to catch errors from anywhere in the components child component tree. Basically this gives us the ability to inform the user that something went wrong and render some fallback UI. We could add this to our App component like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5YZpWGQx96AOlL5a8PnKDA.png" /></figure><p>So now in the state, we’ve just added a check for the error and then we render some fallback UI if one occurs. componentDidCatch() also receives two arguments that allow us to explore our errors further:</p><pre>componentDidCatch(error, info) {}</pre><p>The first is the error itself and the second (info) is the component stack. These arguments are particularly useful to send off to an error reporting service so we can see where the application is breaking in production and fix it.</p><h3>Error Boundaries</h3><p>Our App component has now become what is known as an <a href="https://facebook.github.io/react/blog/2017/07/26/error-handling-in-react-16.html">error boundary</a>. This is defined with 3 key characteristics, to quote from Facebook:</p><blockquote>components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI</blockquote><p>We should now extract our error handing into a reusable component, which following our example app, should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*Dg7O-YAo5-eDhHhw01DRCw.png" /></figure><p>We can now simply wrap other components or bits of JSX inside our error boundary, giving us flexibility as to what is included. For example, we could decide to wrap both the Book component and button inside it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9KVmld-AE_7G1cUtGwRLQ.png" /></figure><p>To sum up, React 16 gives us much better possibilities for both identifying and handling errors when they occur in production applications, ultimately leading to a better user experience and less frustrated developers:-)</p><p>For a more detailed look at all the features of React 16 we highly recommend reading the <a href="https://facebook.github.io/react/blog/2017/09/26/react-v16.0.html">React team’s post about it</a> and Dan Abramov’s post on <a href="https://facebook.github.io/react/blog/2017/07/26/error-handling-in-react-16.html">Error Handing in React 16</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa4e248d45d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript: The beauty of arrow functions]]></title>
            <link>https://medium.com/@richard_13764/javascript-the-beauty-of-arrow-functions-2970efe5b4db?source=rss-3d90c9462fe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2970efe5b4db</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[arrow-functions]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Richard Moss]]></dc:creator>
            <pubDate>Tue, 12 Sep 2017 14:09:20 GMT</pubDate>
            <atom:updated>2017-09-12T14:10:22.473Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*eoGz_UsGWscM3iRX240CvA.png" /></figure><p>Arrow functions are an awesome ES6 language feature for a number of reasons, but we believe there are 3 key reasons they really shine:</p><ol><li>They are more concise</li><li>They allow for implicit returns</li><li>They get their “this” value from the context, meaning it comes from the caller</li></ol><p>Let’s look at some ES5 vs ES6 code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*YcVs6h96vWeDW4PI." /></figure><p>In the above code example we compare the ES5 and ES6 way of grabbing some values from an array of objects.</p><p><strong>More Concise</strong></p><p>The most striking thing is the amount of code, less code means less probability of introducing errors. Secondly it’s obvious that our arrow function has improved readability here, it’s also more declarative. Being concise and declarative with code is especially important when working in teams, it saves time and improves outcomes.</p><p><strong>Implicit returns</strong></p><p>The ability to return values implicitly builds upon the first point, we no longer need to add extra syntax such as the {} and return keyword if they are not needed. This allows for one-line manipulation of arguments, as we saw in our code example above where we return “animal.name” implicitly:</p><pre>animal =&gt; animal.name</pre><p><strong>“This” value from the context</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*1FvLJGtv4Nzkixd6WU_scw.png" /></figure><p>What will we see in our console when we execute fn() ?</p><p>…</p><p><em>The answer is we will see the Window object, because the context here is the Window.</em></p><p>What will we see when we execute obj.fn() ?</p><p>….</p><p><em>We will see the object, because the context here is the object. So context is simply the one who is calling the function.</em></p><p>If this isn’t clear, have a play with the code yourself here: <a href="https://jsbin.com/xoqopadeyo/edit?js,console">https://jsbin.com/xoqopadeyo/edit?js,console</a></p><p><strong>So why is getting the “this” value from the context useful?</strong></p><p>Before we had to bind our functions explicitly to make sure they had the right “this” value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*AM4CMaz5g6oa_L9oUW4_JQ.png" /></figure><p>We can of course continue doing this, but now we have a more concise way of doing the same thing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*hHWwI5ov7MBENJekNR_0sA.png" /></figure><p><strong>Summing up</strong></p><p>Using arrow functions allows us to use a more concise and declarative syntax while eliminating the need for us to bind them explicitly. There are of course a few more things to know about arrow functions which are beyond the scope of this post. However, these are the most important and relevant reasons to use them and what we believe makes them really special :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2970efe5b4db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeanJS supercharged react boilerplate]]></title>
            <link>https://medium.com/@richard_13764/leanjs-supercharged-react-boilerplate-4e57f3bc04ae?source=rss-3d90c9462fe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e57f3bc04ae</guid>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[linting]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[boilerplate]]></category>
            <dc:creator><![CDATA[Richard Moss]]></dc:creator>
            <pubDate>Mon, 08 May 2017 10:14:27 GMT</pubDate>
            <atom:updated>2017-05-08T10:16:09.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*St5crFq6GyphKeEs6ak96w.png" /></figure><h3><strong>Why use a boilerplate?</strong></h3><p>Getting started with react can be a labour intensive process. If you’re just getting started you’ll probably hear a lot of people say “just use a boilerplate!”, the most popular of which is create-react-app. At LeanJS we’ve created an <a href="https://github.com/reactjs-academy/react-leanjs-bolierplate">awesome boilerplate</a> with a unique set of curated features that we use in our projects, incorporating some of the most innovative tools from the react community. This boilerplate is our starting point for building real world apps, we think you’ll love it too :-)</p><h3>A word about yarn</h3><p>You may have noticed we use yarn rather than npm, luckily it’s fully backward compatible so you can always just swap out the word “yarn” for “npm”, and everything will work as expected. For a good summary of the “what, why, how” of yarn, <a href="https://medium.com/@kaayru/what-is-yarn-and-should-we-use-it-dbd8c46de6a">check out this post</a>.</p><h3>Decoupled utils from create-react-app</h3><p><a href="https://github.com/reactjs-academy/react-dev-utils-academy">reactjs-academy/react-dev-utils-academy</a></p><p>Create-react-app is awesome, however it does have an issue when it comes to using it on a regular basis as a boilerplate. The boilerplate itself if very closed and the changes made are very dependent on the structure that Facebook and the creators of the boilerplate decide it should be. But what happens when you want new bits in your project but the curators have changed things like the naming conventions and folder structure? Or better still, adding new features to your boilerplate? In a nutshell, you can’t, you need to fork the repo. If you wanted to add something to a create-react-app you would need to run the “eject” script, this will extract the build dependencies, configs, and scripts and move them right into your project so you can customize everything. But now you are losing the advantage of a neatly abstracted away config, which is why you probably choose to use create-react-app (building faster!).</p><p>In addition, most of the packages are dependencies of the repo itself and so can’t be used separately, which of course is part of the motivation for creating a custom boilerplate.</p><p>A good example of this is the create-react-app script that will display console errors in the browser directly, greatly improving developer workflow. These types of scripts are sometimes updated changed or even deleted, which is why if you’re getting a lot out of it, decoupling them is a must.</p><p>This is why we created <a href="https://github.com/reactjs-academy/react-dev-utils-academy">react-dev-utils-academy</a>, it gives us a decoupled and maintained repo of the react-dev-utils from create-react-app which can be used in conjunction with, or completely separate from create-react-app itself.</p><p>In short create-react-app is a great option if your getting started with React, but if you know react already and want to build a real world app, we believe our boilerplate provides a good option.</p><h3><strong>Built with testing in mind</strong></h3><p>Well tested code is the mark of a professional developer. We use Jest and Enzyme due to their simplicity and efficacy. We’re also planning to integrate testing with React Story Book in the near future. In addition to the test runner you can run “yarn run coverage” to generate a report both in terminal and stored as html:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZTcYWYXqEJ7Tfv26NI4CVQ.png" /></figure><h3>Webpack2</h3><p>Webpack2 is awesome and we’ve added a number of great features including a polyfills.js file (95% browser compatibility), linter checking before build, hot reloading and css transformations for all browsers, to name but a few! To really get stuck in <a href="https://github.com/reactjs-academy/react-leanjs-bolierplate#webpack-2">check out the webpack section in the repo</a>.</p><h3><strong>Performance</strong></h3><p>Here is where our boilerplate sets itself apart from other boilerplates, introducing multiple performance tweaks from the react community via Webpack2 and Babel. Highlights include:</p><ul><li>Faster development builds via caching of previous builds</li><li>Optimized minification and gzipping of files</li><li>File splitting for lazy load or http2 load</li><li>CSS single file generation for performant loading on production build</li></ul><p>With inspiration from: <a href="https://medium.com/@thejameskyle/react-loadable-2674c59de178">Introducing React Loadable</a>, <a href="https://medium.com/dev-channel/progressive-web-app-libraries-in-production-b52cad37d34">Progressive Web App Libraries in Production</a>, and <a href="https://medium.com/dailyjs/react-is-slow-react-is-fast-optimizing-react-apps-in-practice-394176a11fba">React is Slow, React is Fast: Optimizing React Apps in Practice.</a></p><h3>Build:dll</h3><p>Our build:dll script takes advantage of <a href="https://medium.com/@soederpop/webpack-plugins-been-we-been-keepin-on-the-dll-cdfdd6cb8cd7">an underused webpack plugin</a> called DLL. In a nutshell this plugin drastically speeds up the startup time and hot-reload times by adding a separate step in the build toolchain. It works by wrapping all your dependencies in a package that is referenced for your day- to-day development. You only need to update it when your dependencies change. This has the effect of taking a serious load off your webpack complier meaning you can start developing almost instantly.</p><h3>Single Bundle Build or Vendor + App Bundle Build</h3><p>Our boilerplate gives you the choice of running a single bundle build or a split build.</p><p>The main advantage of doing a split build and generating a vendor file is that this will be cached by the browser for a long period of time. This means that on the first load there will be two JS files, but for all subsequent loads it will only be loading the app bundle reflecting any changes you made to your components making it much more performant.</p><p>Check out the section on <a href="https://github.com/reactjs-academy/react-leanjs-bolierplate#vendor--app-bundle-build">Vendor + App Bundle Build in the README</a> to get this going.</p><h3>Linting JS &amp; CSS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*VmvKeChS7Ooun4fpYAnwag.jpeg" /></figure><p>We have included 3 types of linters with auto correction. Supporting JS, JSX, CSS and SCSS. These linters follow the code style rules of “Airbnb” and “Standard”. While in development, our webpack configuration helps you to write better code as it stops compiling if issues are found by ESLint.</p><p>A benefit brought by using <a href="https://github.com/morishitter/stylefmt"><strong>stylefmt</strong></a> for formatting stylesheets is that in addition to correcting code style, it’ll also add cross browser compatibility to your CSS and acts as a linter for your SCSS.</p><p>Another cool feature is that the linters are run before any commit thanks to <a href="https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8"><strong>Pre-commit</strong></a><strong>. </strong>When we create a commit the linters will execute automatically and no commit is generated if the reformat doesn’t pass. This also helps you to save a lot of extra commits that would otherwise be generated due to linting related changes.</p><p>The overall effect is that in development you’ll be forced to write better code, while in production everything is neatly minified.</p><h3>React Story Book</h3><p><a href="https://github.com/storybooks/storybook">React Storybook</a> is a development environment for React UI components. It allows you to browse a component library, view the different states of each component, and interactively develop and test components.</p><p>We use a custom config to supercharge storybook with plugins such as, <a href="https://www.npmjs.com/package/@kadira/storybook-addon-knobs">knobs addon</a>, <a href="https://www.npmjs.com/package/react-storybook-addon-intl">react-storybook-addon-intl</a>, <a href="https://www.npmjs.com/package/@kadira/react-storybook-addon-info">react-storybook-addon-info</a>, <a href="https://www.npmjs.com/package/react-storybook-addon-props-combinations">react-storybook-addon-props-combinations</a> and <a href="https://github.com/sm-react/storybook-addon-material-ui">storybook-addon-material-ui</a>. <a href="https://github.com/reactjs-academy/react-leanjs-bolierplate#react-story-book">Check out our README</a> for an in-depth explanation of each :-)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TxuoKupMwNqsEKyrCdB9cQ.gif" /></figure><h3>Next steps</h3><p>At LeanJS we are building out and further developing our boilerplate, we believe the best way to learn is by doing and we welcome all feedback of your experiences using it!</p><p>We built this boilerplate ourselves based on our belief that it’s important to take a deep-dive under the hood of the tech stack our work relies on, and as we’ve seen, there are many hidden gems and performance enhancements out there that can be taken advantage of by the curious.</p><p>We’ve also designed it to run equally well on mac, linux and windows environments, no development environment exclusivity here ;-)</p><p>Happy react developing!</p><p><strong>Important links:</strong></p><ul><li>The boiler plate!: <a href="https://github.com/reactjs-academy/react-leanjs-bolierplate">https://github.com/reactjs-academy/react-leanjs-bolierplate</a></li><li>React Dev Utils Academy: <a href="https://github.com/reactjs-academy/react-dev-utils-academy">https://github.com/reactjs-academy/react-dev-utils-academy</a></li></ul><p><em>Thanks to the @leanjs Team and @</em><a href="https://github.com/fsdevlondon"><em>marchriv</em></a><em> for the effort put into the creation of the boilerplate.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e57f3bc04ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>