<?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 Matthew Holman on Medium]]></title>
        <description><![CDATA[Stories by Matthew Holman on Medium]]></description>
        <link>https://medium.com/@matthew.holman?source=rss-14f0f179c1df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FrkkZZA7Yg60F_4Dv5xK6w.jpeg</url>
            <title>Stories by Matthew Holman on Medium</title>
            <link>https://medium.com/@matthew.holman?source=rss-14f0f179c1df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:38:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matthew.holman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[React Hooks — useState]]></title>
            <link>https://medium.com/@matthew.holman/react-hooks-usestate-41ff1bf82dd?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/41ff1bf82dd</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[usestate]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Mon, 22 Jul 2019 00:51:34 GMT</pubDate>
            <atom:updated>2019-07-22T00:51:34.002Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Hooks — useState</h3><p>This series explores the various Hooks APIs available in React. In this part of our series, we will explore the useState hook!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*g8Kor6hiXGQ8vdUTgCLaLw.jpeg" /></figure><h3>What is it?</h3><p>The useState hook allows you to use local state in your React code. The useState API expects you to provide a variable name for the state you want to use and a setter function to set the state variable you declare.</p><h3>Syntax</h3><p>To get started, we can declare our useState hook as follows:</p><pre>const [state, setState] = useState(&quot;&quot;);</pre><p>Above, we declare our useState hook using a const. As our first argument, we give our state variable a name of “state”. The second argument in the array is a function used to set our state — we have named the function “setState”. We pass an empty string as the initial state to the useState hook and the declaration is complete!</p><h3>Simple Use</h3><p>The useState hook is commonly used to maintain the state of an input field. Take a look at the simple React component below:</p><pre>import React, { useState } from &#39;react&#39;;</pre><pre>const SimpleInput = () =&gt; {<br>  const [inputVal, setInputVal] = useState(&#39;&#39;);<br>  return (<br>    &lt;div className=&quot;simple-input&quot;&gt;<br>      &lt;input<br>        value={inputVal}<br>        onChange={event =&gt; setInputVal(event.target.value)}<br>      /&gt;<br>      &lt;p&gt;The useState value is: {inputVal}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>export default SimpleInput;</pre><p>Try it out:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Finfallible-cherry-cnn6t%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Finfallible-cherry-cnn6t%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fcnn6t%2Fscreenshot.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/dd750fff6a9fdeef9268394cd55f4f7b/href">https://medium.com/media/dd750fff6a9fdeef9268394cd55f4f7b/href</a></iframe><p>In our example, we utilize the useState hook to control the value of our input element. We use ‘inputVal’ to store the value and ‘setInputVal’ to set the input value when a change occurs. We pass an empty string to our hook to initialize the state.</p><h3>Slightly More Complex</h3><p>Now that you have a basic idea of how the useState hook works, let’s expand the example above to be slightly more complex:</p><pre>import React, { useState } from &#39;react&#39;;<br>import &#39;../styles/simpleInput.css&#39;;</pre><pre>const SetStateExample = () =&gt; {<br>  const [inputVal, setInputVal] = useState(&#39;&#39;);<br>  const [listVals, setListVal] = useState([]);</pre><pre>  const handleSubmit = (e) =&gt; {<br>    e.preventDefault();<br>    setListVal([...listVals, inputVal]);<br>    setInputVal(&#39;&#39;);<br>  };</pre><pre>  return (<br>    &lt;div className=&quot;simple-input&quot;&gt;<br>      &lt;form onSubmit={handleSubmit}&gt;<br>        &lt;input<br>          value={inputVal}<br>          onChange={event =&gt; setInputVal(event.target.value)}<br>          placeholder=&quot;Input some text and press enter...&quot;<br>        /&gt;<br>        &lt;p&gt;The input useState value is currently: {inputVal}&lt;/p&gt;<br>        &lt;hr /&gt;<br>        &lt;p&gt;The listVals useState value is currently:&lt;/p&gt;<br>        {<br>          listVals.length === 0<br>            ? (&lt;p&gt;An empty array.&lt;/p&gt;)<br>            : (<br>              &lt;ul&gt;<br>                {<br>                listVals.map((listVal, index) =&gt; (<br>                  &lt;li key={index}&gt;{listVal}&lt;/li&gt; <br>                ))<br>                }<br>              &lt;/ul&gt;<br>            )<br>        }<br>      &lt;/form&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>export default SetStateExample;</pre><p>Try it out:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fnaughty-currying-ncqdy%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fnaughty-currying-ncqdy%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fncqdy%2Fscreenshot.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/d0137a74bb2b1ce7f64708a19decffb9/href">https://medium.com/media/d0137a74bb2b1ce7f64708a19decffb9/href</a></iframe><p>We have expanded upon our first example to include a new state hook. We utilize the new state in order to keep track of a list of things that the user inputs. Every time a user inputs some text and presses ‘Enter’, the text is added to the list using the ‘setListVal’ function of our new useState hook.</p><h3>Utilizing the Previous State</h3><p>There are many times you may want to know and use the previous state when making a state change using your hook. In such cases, React allows a function to be passed as an argument to the state setter function:</p><pre>import React, { useState } from &#39;react&#39;;</pre><pre>const PrevStateExample = () =&gt; {<br>  const [counter, setCounter] = useState(0);<br>  const handleIncrease = () =&gt; {<br>    setCounter(prevState =&gt; prevState + 1);<br>  };<br>  const handleDecrease = () =&gt; {<br>    setCounter(prevState =&gt; prevState - 1);<br>  };<br>  return (<br>    &lt;div className=&quot;counter-container&quot;&gt;<br>      &lt;button className=&quot;counter-button&quot; onClick={handleDecrease}&gt;<br>        -<br>      &lt;/button&gt;<br>      &lt;p className=&quot;counter-digits&quot;&gt;{counter}&lt;/p&gt;<br>      &lt;button className=&quot;counter-button&quot; onClick={handleIncrease}&gt;<br>        +<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>export default PrevStateExample;</pre><p>Try it out:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fgifted-cdn-o8sii%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fgifted-cdn-o8sii%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fo8sii%2Fscreenshot.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/00957781dba496712a02e1242c868e16/href">https://medium.com/media/00957781dba496712a02e1242c868e16/href</a></iframe><h3>Wrapping Up</h3><p>The useState hook provides a method for you to use local state in your React code. The traditional method of creating a state declaration within a class component and updating the state with setState() is still valid and relevant. However, the new useState hook allows you to utilize local state within a functional component as well!</p><p>I hope this article helped you understand the useState() hook. If you still have any questions, or if I got something wrong (it happens), let me know in the comments below!</p><h4>Sources</h4><p><a href="https://reactjs.org/docs/hooks-reference.htm">Official Docs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41ff1bf82dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS Interview: What is ‘this’?]]></title>
            <link>https://medium.com/@matthew.holman/js-interview-what-is-this-4daaf797dd4?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/4daaf797dd4</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Fri, 12 Jul 2019 22:26:15 GMT</pubDate>
            <atom:updated>2019-07-12T22:26:15.955Z</atom:updated>
            <content:encoded><![CDATA[<p>JS Interview is a series of short articles where we will explore common JavaScript related interview questions. In this article, we will explore what the ‘this’ keyword is and why it’s such a tricky interview question!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*4c-A4QnkiN6FuSLmxs0ZsQ.gif" /><figcaption>What is ‘this’???</figcaption></figure><h3>Simply Put</h3><p>In the English language, we use the pronoun ‘this’ to reference something:</p><blockquote>I’m going to wear <strong>this</strong> jacket.</blockquote><p>or</p><blockquote><strong>This</strong> is my computer. There are many like it, but <strong>this</strong> one is mine.</blockquote><p>Similarly, in the JavaScript language, the ‘this’ keyword is used to reference something — an object (don’t forget, in JavaScript, functions are first-class objects).</p><p>However, the thing that the ‘this’ keyword is referencing can change based on the <em>execution context</em> and how the ‘this’ keyword was invoked…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*RVbD1cMt73Q-VI00307Kyw.gif" /></figure><h3>Wait a second…</h3><p>Your ‘this’ keyword reference can change based on many things, including:</p><ul><li>Is your JavaScript in ‘strict’ mode or non-strict mode?</li><li>How are you invoking the function?</li><li>Is your method being called on an object or as part of a class?</li></ul><p>And because functions are first-class objects and can be passed around, it can be easy to lose track of exactly what ‘this’ is referring to!</p><h3>Strict vs un-strict</h3><p>The ‘this’ keyword can refer to different objects depending if you are operating in ‘strict’ mode or not.</p><p>If you were not operating in strict mode and invoked the following function, it would refer to the global object:</p><pre>function whatIsThis() {<br>    console.log(this);<br>}</pre><p>However, if you were in strict mode and invoked the same function, the ‘this’ keyword would be undefined!</p><h3>Object method</h3><p>If we create an object with a method, such as:</p><pre>const myObject = {<br>    greeting: &#39;Hello darkness my old friend.&#39;,<br>    greet: function () {<br>        console.log(this.greeting);<br>    }<br>};</pre><p>And then we invoke the method with:</p><pre>myObject.greet();</pre><p>The console output would be the greeting we expected:</p><pre>Hello darkness my old friend.</pre><p>However, if we were to create a new variable that referenced the greet function of myObject and tried to invoke it:</p><pre>const greetAgain = myObject.greet;<br>greetAgain();</pre><p>The console output would be <em>undefined</em>!</p><p>It is undefined because the method is being invoked in the global context, rather than the context of the myObject variable. When it is invoked in the global context, the ‘this’ keyword refers to the global object, rather than our myObject variable.</p><p>If we want to get the greeting, we need to add the variable to the global context. If we revise our code to add the greeting variable:</p><pre>const greeting = &quot;Howdy from Texas!&quot;;<br>const greetAgain = myObject.greet;<br>greetAgain();</pre><p>The new console output will be:</p><pre>Howdy from Texas!</pre><h3>Nested objects</h3><p>When invoking a method that utilizes the ‘this’ keyword within a nested function, ‘this’ takes the reference of the immediate object calling the function.</p><p>If we had the following object:</p><pre>const parentObject = {<br>  g1: &#39;Hey, I&#39;m the parent!&#39;<br>  childObject: {<br>    g2: &#39;Hey, I&#39;m the child!&#39;<br>    makeAnnouncement: function() {<br>      console.log(this.g1 + &#39; and &#39; + this.g1);<br>    }<br>  }<br>};</pre><p>And invoked the makeAccouncement() method:</p><pre>parentObject.childObject.makeAnnouncement();</pre><p>It would output to the console:</p><pre> and Hey, I&#39;m the child!</pre><p>That is because g1 is not available to childObject. There are several ways to bind the parent object variables to the child object, which we will cover later.</p><h3>Function.prototype.call()</h3><p>You can invoke a method with .call(). When you do so, it calls the function with a given ‘this’ value and arguments. Invoking a function directly with the parenthesis syntax is the same thing as invoking with .call(). The ‘this’ reference again depends on if you are in ‘strict’ mode or not. If we have the following function:</p><pre>function greet(person) {<br>    console.log(&quot;Hello &quot; + person);<br>}</pre><p>Invoking it in strict mode with:</p><pre>greet(&quot;Matthew&quot;);</pre><p>Would be the same as invoking it with the call method with an ‘undefined’ this argument:</p><pre>greet.call(undefined, &quot;Matthew&quot;);</pre><p>Or calling it in non-strict mode with the window object as the ‘this’ argument:</p><pre>greet.call(window, &quot;Matthew&quot;);</pre><h3>Function.prototype.apply()</h3><p>You can also invoke a method with .apply(). The apply method is similar to the .call() method, except it accepts a single array of arguments rather than an arguments list.</p><h3>Function.prototype.bind()</h3><p>Sometimes you may want to invoke a function and insure it always maintains a particular ‘this’ value. By invoking a method with .bind(), we wrap the original function with a new function that ensures the original function is called with the specified ‘this’ value.</p><p>When the code is run below, the printName() function returns “Matthew” because it was invoked at the global scope and the name variable was assigned the value “Matthew” at the global scope:</p><pre>this.name = &quot;Matthew&quot;; //&quot;Matthew&quot; is assigned to the global object<br>const person = {<br>  name: &quot;Mark&quot;,<br>  age: 21,<br>  getName: function() { return this.name; }<br>}<br>const printName = person.getName();<br>printName();</pre><p>If we wanted our function to return “Mark”, we could use bind:</p><pre>this.name = &quot;Matthew&quot;; //&quot;Matthew&quot; is assigned to the global object<br>const person = {<br>  name: &quot;Mark&quot;,<br>  age: 21,<br>  getName: function() { return this.name; }<br>}<br>const printName = person.getName.bind(person);<br>printName();</pre><h3>Object.create()</h3><p>The Object.create() method creates a new object, using an existing object as the prototype of the newly created object. The object inherits properties from the parent object, so if we were to create a new object from the ‘person’ object above:</p><pre>const funnyPerson = Object.create(person);<br>funnyPerson.isFunny = true;<br>funnyPerson.lastName = &quot;Jefferson&quot;</pre><p>We can invoke the getName method on the newly created funnyPerson object, and it would inherit the name from the parent object, even though we never explicitly assigned a name to funnyPerson:</p><pre>console.log(funnyPerson.getName());</pre><p>and the output to the console would be: “Mark”</p><h3>The ‘new’ operator</h3><p>Creating an object with the ‘new’ operator allows it to inherit properties up the parent chain, similar to using Object.create().</p><h3>Conclusion</h3><p>There you have it! Easy peasy right? Soooo, if you get asked this question during an interview, feel free to take up the entire allotted time breaking down what the ‘this’ keyword could be referencing in various scenarios. If I helped clear things up, please let me know 👏! If you still have any questions, or if I got something wrong (it happens), let me know in the comments below!</p><p>If you enjoyed this article, you may also enjoy some others from the JS Interview series:</p><p><a href="https://medium.com/@matthew.holman/js-interview-explain-event-delegation-b619ed7cd544">JS Interview: Explain Event Delegation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*QW4oGxrM0iLJjjPXoxJvAQ.gif" /></figure><p><strong>Sources</strong><br><a href="https://www.vojtechruzicka.com/javascript-this-keyword/">Vojtech Ruzicka’s Programming Blog</a><br><a href="https://hackernoon.com/lets-get-this-this-once-and-for-all-f59d76438d34">Lets get this `this` once and for all</a><br><a href="https://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/">Understanding JavaScript Function Invocation and “this”</a><br><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">MDN: Object</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4daaf797dd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS Interview: Explain Event Delegation]]></title>
            <link>https://medium.com/@matthew.holman/js-interview-explain-event-delegation-b619ed7cd544?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/b619ed7cd544</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[event-delegation]]></category>
            <category><![CDATA[event-bubbling]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Mon, 18 Feb 2019 22:45:48 GMT</pubDate>
            <atom:updated>2019-02-18T22:45:48.033Z</atom:updated>
            <content:encoded><![CDATA[<p>JS Interview is a series of short articles where we will explore common JavaScript related interview questions. In this article, we will explore event delegation, event bubbling and how we can use them both to our advantage!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qaes_-OsZaAXTnw67zHjsw.jpeg" /></figure><h3>What is event delegation?</h3><p>Event delegation is when a parent element automatically adds event listeners to its children elements. The event listener will fire anytime an event is triggered on the child element, due to event “bubbling” (event propagation).</p><h3>What is event “bubbling” / event propagation?</h3><p>When an event is triggered from an element, the event handler / event listener tied to that event is called. When an event is fired on an element that has parent elements, it runs through a “bubbling” phase. During the “bubbling” phase, the browser checks to see if the element that triggered the event has an event handler registered to it. If it does, it runs the event handler. If it does not, it moves to the parent element and checks if it has an event handler registered to it. The browser continues to move up the chain of parent elements, checking for and executing registered event handlers, until it reaches the root element.</p><h3>Can I prevent event bubbling?</h3><p>Yes! In your event handler, you can add the stopPropagation() method to the event. For example, you could add the following to an onClick() event handler:</p><pre>myElement.handleOnClick = (e) =&gt; {<br>  e.stopPropagation();<br>  // Add code to handle the even here<br>}</pre><h3>When would you use event delegation?</h3><p>Event delegation can be extremely useful when you want to automatically set an event listener on child elements. For example, say you want to add an event listener to all the &lt;li&gt; elements of an &lt;ul&gt;. However, the unordered list is dynamically generated, based on some data received from an API call. It would be impossible to attach an event handler to each &lt;li&gt; element individually, but you could attach it to the &lt;ul&gt; element and it would be delegated to each of the child &lt;li&gt; elements!</p><p>Take a look at the code below. We attach a click handler to the parent &lt;ul&gt; and it is automatically delegated to each &lt;li&gt; element:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Frjppwzm7np&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Frjppwzm7np&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Frjppwzm7np%2Fscreenshot.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/9d7d376d9bd61d0cc6b3adbff6954b2f/href">https://medium.com/media/9d7d376d9bd61d0cc6b3adbff6954b2f/href</a></iframe><p>Hopefully that has cleared up some confusion. If you have any questions, leave a comment below. If you found this article helpful, please give a 👏!</p><p><strong>Sources</strong></p><p><a href="https://github.com/yangshun/front-end-interview-handbook/blob/master/questions/javascript-questions.md#explain-event-delegation">The Front End Interview Handbook</a></p><p><a href="https://stackoverflow.com/questions/1687296/what-is-dom-event-delegation">Stack Overflow</a></p><p><a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events">MDN — Events</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b619ed7cd544" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is a Redux selector?]]></title>
            <link>https://medium.com/@matthew.holman/what-is-a-redux-selector-a517acee1fe8?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/a517acee1fe8</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Wed, 04 Jul 2018 01:57:33 GMT</pubDate>
            <atom:updated>2019-04-23T00:42:15.987Z</atom:updated>
            <content:encoded><![CDATA[<p>I was tasked with helping to build out the Redux architecture of a single page application at work. I have built plenty of projects with Redux, but never had to seriously consider performance at scale until this application. As I began doing some research, I repeatedly ran across “selectors”, but had no clue what they were. This article will answer that question for you and hopefully help you determine if they are appropriate for your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*z4nNci9MULCHJDzRrAuyAw.png" /></figure><p>A “selector” is simply a function that accepts Redux state as an argument and returns data that is derived from that state. Bam! The end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*3J_DHmv9IHDm27PEg6AXag.gif" /><figcaption>No no no. That’s not the end.</figcaption></figure><p><strong>Why should you use a selector?</strong></p><p>It is a best practice to keep your Redux store state minimal and derive data from the state as needed. Selectors help with that. They can compute derived data, allowing Redux to store the minimal possible state. Selectors are also very efficient. A selector is not recomputed unless one of its arguments changes.</p><p><strong>If selectors are so useful, why haven’t I heard of them before?</strong></p><p>The Redux documentation doesn’t talk much about selectors as a core concept. However, the <a href="http://redux.js.org/docs/FAQ.html#what-should-my-file-structure-look-like-how-should-i-group-my-action-creators-and-reducers-in-my-project-where-should-my-selectors-go">FAQ in the Redux documentation</a> states:</p><blockquote>It’s generally suggested that selectors are defined alongside reducers and exported, and then reused elsewhere (such as in mapStateToProps functions, in async action creators, or sagas) to colocate all the code that knows about the actual shape of the state tree in the reducer files.</blockquote><p>Selectors are also mentioned in the official Redux docs section on <a href="http://redux.js.org/docs/recipes/ComputingDerivedData.html">Computing Derived Data</a>. They are covered more thoroughly in Dan Abramov’s <a href="https://egghead.io/courses/building-react-applications-with-idiomatic-redux">second series of Redux videos</a>, particularly in <a href="https://egghead.io/lessons/javascript-redux-colocating-selectors-with-reducers">Redux: Co-locating Selectors with Reducers</a>.</p><p><strong>A few examples…</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*05ILrmyLs_sSHqpG1LtFwg.gif" /><figcaption>This is definitely not a selector.</figcaption></figure><p>We have discussed the merits of selectors enough, let’s finally dive into a few examples! Below is a simple selector function for retrieving a list of users from the store:</p><pre>selectUsers = state =&gt; state.users;</pre><p>We can make the above selector slightly more complex by getting user IDs:</p><pre>selectUserIds = state =&gt; state.users.map(user =&gt; user.id);</pre><p>And just to drive the point home, below is an even more complex selector to select users with a provided name:</p><pre>selectUserIdsOfName = (state, name) =&gt; state.users.filter(user =&gt; user.name === name);</pre><p><strong>Best practices…</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*1ezRVpzjQBii-pigFTglXQ.jpeg" /></figure><p>It is a best practice to give your selector function a name that contains “selector”. I prefer to use ‘select’ as a prefix, but it’s also common to use ‘Selector’ as a suffix (i.e. userIdsSelector instead of selectUserIds).</p><p>It is also common practice to keep your selector near the appropriate reducer. That way, if you change the shape of the state, it is easy to remember to change your selector as well.</p><p>Below is an example of a selector bundled with a reducer. We’ll use the <a href="https://redux.js.org/basics/reducers#handling-actions">reducer example</a> from the official Redux docs:</p><pre>// Reducer<br>function todoApp(state = [], action) {<br> switch (action.type) {<br>   case GET_ALL_TODOS:<br>     return {<br>       todos: action.data.todos<br>     };<br>   default:<br>     return state;<br> }<br>}</pre><pre>// Selector<br>function getIncompleteTodos(state) {<br>  return state.todos.filter((todo) =&gt; {<br>    return !todo.completed<br>  });<br>}</pre><p>Now, instead of using something like the following in a smart component’s mapStateToProps() function:</p><pre>function mapStateToProps(state) {<br>  return {<br>    incompleteTodos: state.todos.filter((todo) =&gt; {<br>      return !todo.completed<br>    });<br>  }<br>}</pre><p>We could use the newly created selector in its place:</p><pre>function mapStateToProps(state) {<br>  return {<br>    incompleteTodos: getIncompleteTodos(state)<br>  };<br>}</pre><p>The code is more concise and we have made a big step toward encapsulating our state tree. The component no longer cares how todos are stored in the state tree and it will be much easier to refactor if the state tree needs to be updated!</p><p><strong>Memoization</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*5SYtdPNI87MTBlCHK7CaGA.png" /></figure><p>The use of selectors in your application can also provide performance optimizations. Let’s say you have a component that needs to run an intensive sorting operation on the store’s state in order to get the data it needs. If you were to perform the operation in your mapStateToProps() function, without the use of a selector, the operation would run <strong><em>every</em></strong> time a dispatched action caused the state to update!</p><p>It would be great if we could only run the expensive sorting operation only when the data we are running the operation on changes. This is where the concept of memoization comes to the rescue.</p><p>Memoization is a form of caching. It involves tracking inputs to a function, and storing the inputs and the results for later reference. If a function is called with the same inputs as before, the function can skip doing the actual work, and return the same result it generated the last time it received those input values.</p><p>The official Redux docs <a href="https://redux.js.org/recipes/computing-derived-data#motivation-for-memoized-selectors">briefly discuss memoization</a>. There is also an amazing Redux middleware library for creating memoized selectors called <a href="https://github.com/reduxjs/reselect">Reselect</a>:</p><p><strong>Reselect</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BpaqVMW2RjQAg9cFHcX1pw.png" /><figcaption>Redux Reselect middleware to the rescue!</figcaption></figure><p>We have been creating our own selectors in the examples above, but there is an excellent library out there called Reselect that helps with creating memoized selectors.</p><p>I won’t dive in to the specifics of using Reselect in this article, but I strongly encourage you to check out the <a href="https://github.com/reduxjs/reselect#table-of-contents">official Reselect docs</a>! In addition to the official docs, I ran across <a href="https://blog.isquaredsoftware.com/2017/12/idiomatic-redux-using-reselect-selectors/">a superb article</a> that dives into using the Reselect library and how to further optimize your React-Redux applications with Reselect.</p><p><strong>Recap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*yn3NMy-f9-hqQwXqFJ2Atw.png" /><figcaption>TL;DR</figcaption></figure><p>A selector is a function that accepts Redux state as an argument and returns data that is derived from that state. Selectors can provide performance optimizations to your application and can also help you encapsulate your global state tree. If your application is growing large and unwieldy, you may benefit from creating your own selectors or using a library such as Reselect, which utilizes memoized selectors.</p><p><strong><em>Additional Resources</em></strong></p><ul><li><a href="https://www.youtube.com/watch?v=frT3to2ACCw">Reactcasts episode on selectors</a></li><li><a href="http://randycoulman.com/blog/2016/09/13/encapsulating-the-redux-state-tree/">Randy Coulman’s blog series on selectors</a></li><li><a href="https://hackernoon.com/selector-pattern-painless-redux-store-destructuring-bfc26b72b9ae">Selector Pattern: Painless Redux Store Destructuring</a></li><li><a href="https://egghead.io/lessons/javascript-redux-colocating-selectors-with-reducers">Redux: Colocating Selectors with Reducers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a517acee1fe8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Redux Ducks?]]></title>
            <link>https://medium.com/@matthew.holman/what-is-redux-ducks-46bcb1ad04b7?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/46bcb1ad04b7</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Fri, 08 Jun 2018 21:44:32 GMT</pubDate>
            <atom:updated>2018-06-08T21:44:32.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRjEu51j_cowg0JrWdB_fA.jpeg" /></figure><p>I was in the process of implementing Redux on a large React SPA at work. I had already setup the file structure as I had seen and used before on smaller applications. However, I began to wonder if my setup would scale well as the application grew. A colleague suggested I look into ‘Redux Ducks’. I thought ‘That’s a silly name…’ and started to do some research. Below is a synopsis of my research:</p><p>Ducks is a modular pattern that collocates actions, action types and reducers.</p><p>According to the <a href="https://github.com/erikras/ducks-modular-redux">Ducks proposal</a>:</p><blockquote>A module…</blockquote><blockquote>1. MUST export default a function called reducer()</blockquote><blockquote>2. MUST export its action creators as functions</blockquote><blockquote>3. MUST have action types in the form npm-module-or-app/reducer/ACTION_TYPE</blockquote><blockquote>4. MAY export its action types as UPPER_SNAKE_CASE, if an external reducer needs to listen for them, or if it is a published reusable library</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*ryV_mmL_0DFrLiWF4Yzmug.jpeg" /><figcaption>Getting your ducks in a row…</figcaption></figure><p>Modular? Working with React, I <em>love </em>modular. But, what does a real module look like? Well, here’s an example straight from the Ducks proposal:</p><pre>// Actions<br>const LOAD   = &#39;my-app/widgets/LOAD&#39;;<br>const CREATE = &#39;my-app/widgets/CREATE&#39;;<br>const UPDATE = &#39;my-app/widgets/UPDATE&#39;;<br>const REMOVE = &#39;my-app/widgets/REMOVE&#39;;<br><br>// Reducer<br>export default function reducer(state = {}, action = {}) {<br>  switch (action.type) {<br>    // do reducer stuff<br>    default: return state;<br>  }<br>}<br><br>// Action Creators<br>export function loadWidgets() {<br>  return { type: LOAD };<br>}<br><br>export function createWidget(widget) {<br>  return { type: CREATE, widget };<br>}<br><br>export function updateWidget(widget) {<br>  return { type: UPDATE, widget };<br>}<br><br>export function removeWidget(widget) {<br>  return { type: REMOVE, widget };<br>}<br><br>// side effects, only as applicable<br>// e.g. thunks, epics, etc<br>export function getWidget () {<br>  return dispatch =&gt; get(&#39;/widget&#39;).then(widget =&gt; dispatch(updateWidget(widget)))<br>}</pre><p>Finally, here is a trivial <a href="https://github.com/goopscoop/ga-react-tutorial/blob/6-reduxActionsAndReducers/src/redux/modules/toDoApp.js">ToDo app example on GitHub</a>, created by Cody Barrus.</p><p>We did not end up using the Redux Ducks pattern in our codebase, but I will explain my experiences using Ducks and the implementation we ended up using in another article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46bcb1ad04b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing URL Hash / Query with Jest]]></title>
            <link>https://medium.com/@matthew.holman/testing-url-hash-query-with-jest-8165f26ab94e?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/8165f26ab94e</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 21:18:18 GMT</pubDate>
            <atom:updated>2018-08-15T14:50:26.044Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*bQ7s-PbY_aW3PthOt-iNFw.png" /></figure><p>I’m developing part of an application that utilizes query strings to enable deep linking within a certain React component. I needed to test that the hash was correctly parsed and the view was correctly updated.</p><p>When a user selects certain options that affect the view, the application updates the url hash with a query string. An example URL with query string hash may be:</p><pre>http://myapp.com/user/list?limit=25&amp;offset=2&amp;filterQuery=Matthew</pre><p>The application utilizes ‘parse’ from the <a href="https://github.com/ljharb/qs">qs library</a> to parse the query. It then does some analysis on the query and updates the state based on the result. I had never tested any part of the URL before in my unit tests, so my first step was to make sure I could access the correct area of the DOM and set the query. I added a console.log() to my first test, to make sure the hash was being updated:</p><pre>const newUrl = &#39;list?limit=25&amp;offset=2&amp;filterQuery=Matt&#39;;</pre><pre>Object.defineProperty(window.location, &#39;hash&#39;, {<br>  writable: true,<br>  value: newUrl<br>});</pre><pre>console.log(window.location.hash);</pre><p>By using the console.log and running the test, I was able to verify the hash was indeed set as expected.</p><p>Next, I ran an instance of the parsing method and checked that the state was updated as expected. The full test looked like:</p><pre>it(&#39;Parses URL params and correctly updates the state&#39;, () =&gt; {</pre><pre>  const wrapper = shallow(<br>    &lt;MyComponent {...props1} /&gt;<br>  ).first().shallow();</pre><pre>  const newUrl = &#39;list?limit=25&amp;offset=2&amp;filterQuery=Matt&#39;;</pre><pre>  Object.defineProperty(window.location, &#39;hash&#39;, {<br>    writable: true,<br>    value: newUrl<br>  });</pre><pre>  wrapper.instance().parseHash();<br>  expect(wrapper.state().pagination.limit).to.equal(25);<br>  expect(wrapper.state().pagination.offset).to.equal(2);<br>  expect(wrapper.state().filter.filterQuery).to.equal(&#39;Matt&#39;);</pre><pre>});</pre><p>It worked! There isn’t anything too complex in the unit test above, but I had never tested URL params before and wanted to share my experience with you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8165f26ab94e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn React: Foundation II]]></title>
            <link>https://medium.com/@matthew.holman/learn-react-foundation-ii-19f191b94b55?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/19f191b94b55</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Wed, 10 Jan 2018 00:29:37 GMT</pubDate>
            <atom:updated>2018-01-10T00:29:37.389Z</atom:updated>
            <content:encoded><![CDATA[<p>React Skyscraper is a series of coding tutorials that will build upon each other to help you learn and master React! In <a href="https://medium.com/@matthew.holman/learn-react-foundation-i-81154278f7f8"><strong>Foundation I</strong></a>, we setup our initial dependencies, the webpack and the webpack dev server. This is the second tutorial of the series, where we’ll finish the setup groundwork and add our first JSX to the React application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*-RUHwiaBg7C7YA-t1A_AhQ.jpeg" /></figure><p><strong>Babel</strong></p><p><a href="https://babeljs.io/">Babel</a> is a JavaScript compiler that will allow us to use the latest <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Language_Resources">ECMAScript</a> (ES6 &amp; beyond) and JSX, even though browsers may not support it yet. We’ll add it to our project with the following command: yard add babel-loader babel-core babel-preset-env babel-preset-react --dev.</p><p>Next, we’ll need to add some code to our package.json file to integrate babel support:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*iUS9KkFyF7ydEKqDP7dMNQ.jpeg" /></figure><p>And then we’ll need to add our list of modules with the <a href="https://github.com/babel/babel-loader">babel-loader</a> to webpack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EgCUiyL3EpHwGomM0cOE8A.jpeg" /></figure><p>Uhhhh….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*BEi6U5JNZ1msv_EhKdmjPQ.gif" /></figure><p>That was a lot, so let’s break it down real quick before we move on:</p><p>Webpack treats every file as a module. It supports modules through “loaders”, which describe how to incorporate non-JavaScript modules and dependencies into our project. Webpack has a <a href="https://webpack.js.org/concepts/#loaders">great explanation on loaders</a>, so we won’t dive into it here.</p><p>The module: {} section of code tells webpack which modules we want to incorporate into our application.</p><p>The rules: [] array tells webpack what to do with a particular file type when it runs across it. Each rule is an object that must contain a test: and a use: {} key value pair. The test: line of code uses a regular expression to tell webpack what type of file we want to run the rule on. In the case above, we are telling webpack to test all files and when it runs across a .js* file, to use the babel-loader we installed previously with the env and react presets.</p><p>Ok. We have everything setup and we’re finally ready to start coding some react. I know that was a lot to get setup, but I’ll show you a convenient shortcut at the beginning of the next article.</p><p><strong>REACT. Finally.</strong></p><p>Let’s open our index.js file, remove the console.log() and add the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-GA0FjjDLFylhU34-m-pA.jpeg" /></figure><p>The first two statements import the dependencies required for React. I encourage you to <a href="https://facebook.github.io/react/docs/hello-world.html">read the official React docs</a> to learn more about the dependencies, why you need two separate imports and just to familiarize yourself with React.</p><p>The ReactDOM.render() function tells React that we want to render something to <a href="https://www.w3schools.com/js/js_htmldom.asp">the DOM</a>. The first argument is the element we want to render and the second argument is the container where we want to render the element (That’s why we named the &lt;div id=&quot;app&quot;&gt; in our index.html file).</p><p>Go ahead and switch back to your terminal and fire up what we have already with the command yarn start. You should see the following pop-up automagically in your web browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zNELt_4ha8A3sHoZVZlMwA.jpeg" /></figure><p>Bam! We have our first React code rendering to the browser!</p><p>I know that was a <em>ton</em> of setup just to get that tiny bit of React to render, but I’ll show you a nice shortcut and a few tips and tricks in the next part of this series.</p><h3><strong>Learn React: Foundation III</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19f191b94b55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn React: Foundation I]]></title>
            <link>https://medium.com/cloudboost/learn-react-foundation-i-81154278f7f8?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/81154278f7f8</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[learn-react-js]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Tue, 12 Sep 2017 21:08:59 GMT</pubDate>
            <atom:updated>2017-09-17T16:50:13.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*-RUHwiaBg7C7YA-t1A_AhQ.jpeg" /></figure><p>React Skyscraper is a series of coding tutorials that will build upon each other to help you learn and master React! This is the first tutorial of the series, where we’ll lay the foundation to build-up a great React application.</p><p>There are quite a few things we need to get setup before we can start coding. So, without further ado:</p><p><strong>Getting Setup</strong></p><ol><li>Install <a href="https://nodejs.org/en/download/package-manager/">Node</a>.</li><li>Install <a href="https://yarnpkg.com/en/docs/install">Yarn</a>.</li><li>Create a new project folder: mkdir reactSkyscraper</li><li>Change into your project folder and we’ll initialize our project with yarn init. You can type in answers to all the questions or just hit enter for all of them to set them to the default answer.</li><li>Install <a href="https://webpack.js.org/">webpack</a> and the webpack-dev-server: yarn add webpack webpack-dev-server --dev</li><li>Install react and react-dom: yarn add react react-dom</li><li>Let’s create a folder called ‘build’ to hold the output bundle that webpack will create for us: mkdir build</li><li>We’ll also create a source directory ‘src’ and a sub-directory within it called ‘components’ to hold our React components. This is a common directory structure used in React applications.</li><li>At this point, your directory structure should look like this:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*54nsGGo_BCcBBEfP02rFFA.jpeg" /><figcaption>Initial directory structure for our app.</figcaption></figure><p>Your package.json file should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*upX34uISsHmB-7smGewQ-w.jpeg" /></figure><p><strong>Splainin’</strong></p><p>We just did a bunch of setup without much explanation, so allow me to break it down for you a bit…</p><p>When we create our application with React, which is a JavaScript framework, our web browser(s) won’t know how to run the application. That’s where Webpack comes in and saves the day like a badass.</p><p>From the <a href="https://webpack.js.org/concepts/">Webpack page itself</a> “ When webpack processes your application, it recursively builds a <em>dependency graph</em> that includes every module your application needs, then packages all of those modules into a small number of <em>bundles</em> — often only one — to be loaded by the browser”.</p><p><strong>Version Control AKA the “Save” button</strong></p><p>At this point, it’s a good idea to setup a Git repository so we can save our progress on the application.</p><p>If you’re not familiar with Git, or why you should use version control, take a break and check-out the following:</p><ul><li><a href="http://rogerdudler.github.io/git-guide/">Git — The Simple Guide</a></li><li><a href="https://git-scm.com/book/en/v1/Getting-Started-About-Version-Control">About Version Control</a></li></ul><p>After you have setup your git repository, don’t forget to add a .gitignore file to prevent committing unnecessary files (mainly, all the node modules). If you’ve never created or used a .gitignore file before, feel free to use <a href="https://github.com/facebook/react/blob/master/.gitignore">this one from Facebook</a> or the template below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqZsR1npVLxUAjXNMfmRuQ.jpeg" /><figcaption>.gitignore file for our project</figcaption></figure><p>Let’s go ahead and add everything we’ve setup thus far and push it to our git repository with an initial commit:</p><p>git add -A<br>git commit -m &quot;Initial commit&quot;<br>git push origin master</p><p>Phew. Now that’s out of the way, let’s get started with…</p><p><strong>Webpaaaaaaaaack</strong></p><p>Webpack requires a very specifically named configuration file in order to do its magic. We’ll create a filed named <strong>webpack.config.js </strong>in the root directory of our project to appease webpack. Our initial webpack configuration will consist of the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*Ie8IQmTyiyJAElvvVi9Cjg.jpeg" /></figure><p>The first line of code is requiring the <a href="https://docs.nodejitsu.com/articles/file-system/how-to-use-the-path-module/">path module</a> to make our path manipulation easier. The module.exports allows our settings to be exported as a module object — <a href="http://www.tutorialsteacher.com/nodejs/nodejs-module-exports">read more about that here</a> if you wish.</p><p>The entry key/value pair tells webpack where to enter our app and figure out all it’s dependencies. We haven’t created that file yet, so let’s go ahead and create a file called index.js in the /src directory. Next, add a console.log(&quot;Oh my. It works!&quot;); line to theindex.js file. We’ll beef-up our index.js file later, but we’re using the console.log() to verify everything is working.</p><p>The output key/value pair tells webpack where to put the bundle of joy it will create.</p><p>In addition to the JavaScript bundle that webpack will generate for us, we need to create a html file in our /build folder.</p><p><strong>Public HTML</strong></p><p>We’ll create a standard HTML file. Our HTML file will have a &lt;div&gt; with an id=&quot;app&quot; attribute that our React app will use as an entry point. Your index.html file should look somewhat like the file below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EgmXM-6XjYuLeuQ_OG9jYg.jpeg" /></figure><p><strong>Webpack Dev Server</strong></p><p>We installed webpack-dev-server earlier, but now we need to add some configuration options to webpack. We’ll tell the dev server to serve our bundle from the /build folder we setup with contentBase: &#39;./build&#39;. Your webpack.config.js file should now look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TjvnwcCglMNqWWTD8BZY0g.jpeg" /></figure><p>We also need to add a script to our package.json file to tell it to run our server. We’ll add a &quot;scripts&quot;: section to our package.json file and create a script to start our server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJDLPUvOj4_FBjVPgpl7qA.jpeg" /></figure><p>The --open options will automatically open the URL in your default browser. Go ahead and remove that option if you don’t want the app to auto start in your default browser.</p><p><strong>Does this thing work?</strong></p><p>We’ve made quite a bit of progress, so let’s take a second to make sure everything we’ve setup so far is working. Make sure you have saved the progress we’ve made in all of the files. Open up your terminal, make sure you’re in the root directory and enter the command: yarn start to test it out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_OT8xg3pw1X8effQnvwtw.jpeg" /></figure><p>You should see a new browser window/tab open with a blank screen. If you open up the browser console, you should see the output from our conosole.log() statement. Here are a few links to open the dev tools in various browsers: <a href="http://anti-code.com/devtools-cheatsheet/">Chrome </a>| <a href="https://developer.mozilla.org/en-US/docs/Tools/Browser_Console">Firefox </a>| <a href="https://www.youtube.com/watch?v=8e47ianJYGg">IE </a>| <a href="https://developer.apple.com/library/content/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/GettingStarted/GettingStarted.html">Safari</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3NO0AaM_XaKsD7t3X6lSg.jpeg" /></figure><p>Great job. We’ve gone through quite a bit of configuration and setup for our application, but we still have a few more things to setup before we can start coding in React. Let’s take a quick break and continue in the next section, where we will setup Babel, our webpack loaders and start coding some React (fin-a-lly):</p><h3>React Skyscraper: Foundation II (coming soon)</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81154278f7f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/learn-react-foundation-i-81154278f7f8">Learn React: Foundation I</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS Bytes: Double Quote vs Single Quote vs Backtick]]></title>
            <link>https://medium.com/cloudboost/js-bytes-double-quote-vs-single-quote-vs-backtick-44e36c390dbd?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/44e36c390dbd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es2015]]></category>
            <category><![CDATA[es2016]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Tue, 29 Aug 2017 22:50:08 GMT</pubDate>
            <atom:updated>2017-08-30T18:13:14.557Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HP8l7LMMt7Sh5UoO1T-yLQ.png" /><figcaption>JS Bytes : ‘’ vs “” vs ``</figcaption></figure><p>You’ve probably seen both single quotes and double quotes used in JavaScript. I wondered when I should be using single quotes ‘’ vs double quotes “” vs backticks `` in my code and wanted to share that info with the other wonderers out there.</p><p><strong>Single quotes and double quotes behave in <em>exactly </em>the same way in JavaScript.</strong></p><p>The most important thing is to be consistent with your use of single vs double quotes.</p><p>If you’re a stickler for convention, I would read and follow <a href="https://github.com/airbnb/javascript#strings">Airbnb’s style guide regarding strings</a>.</p><p>Backticks aka “template literals” aka “template strings” aka “fancy strings” were introduced in the ES2015 specifications. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">MDN</a> states “ Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them. They were called “template strings” in prior editions of the ES2015 specification”.</p><p>Backticks are commonly used for multi-line strings or when you want to interpolate an expression within your string.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44e36c390dbd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/js-bytes-double-quote-vs-single-quote-vs-backtick-44e36c390dbd">JS Bytes: Double Quote vs Single Quote vs Backtick</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[create-react-app in production?]]></title>
            <link>https://medium.com/@matthew.holman/reactcreate-react-app-in-production-f819bbdeb624?source=rss-14f0f179c1df------2</link>
            <guid isPermaLink="false">https://medium.com/p/f819bbdeb624</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[learn-react-js]]></category>
            <category><![CDATA[react-js-tutorials]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Matthew Holman]]></dc:creator>
            <pubDate>Fri, 25 Aug 2017 17:44:43 GMT</pubDate>
            <atom:updated>2017-08-30T18:10:12.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*2aquNYnmp7YHa2TeefS9Ew.gif" /></figure><p>During a recent interview programming demonstration, I was asked to create a simple react-based blog application. There was a time constraint and bonus points for adding certain features. To begin the process I was going to scaffold the project with create-react-app when I was told “Nobody uses create-react-app in production, don’t use it for this exercise”.</p><p>I was a bit taken-aback, but lacking major production-ready SPA experience, I didn’t question the statement. But it bugged me. Shortly afterwards, I began seeing a lot of conversations on using create-react-app in production.</p><p>Today I noticed that Dan Abrimov himself <a href="https://twitter.com/dan_abramov/status/898998401819389952">tweeted about the topic</a>!</p><p>After reading through <a href="https://github.com/facebookincubator/create-react-app/issues/2980">the open issue created on the create-react-app repo</a>, it appears that there are plenty of people using create-react-app in their production applications. There are some YC alums using it, some IBM employees using it for internal projects and as you would expect, many side projects that use create-react-app.</p><p>If you are considering using create-react-app in production yourself, I’ve included some links below to some sites I found useful in my research. If you have any additional resources or are using CRA yourself in production, please share!</p><ul><li><a href="https://daveceddia.com/create-react-app-express-production/">Dave Ceddia’s tutorial “Create-react-app in production with Express”</a></li><li>Andrew Van Sleer’s Egghead.io tutorial <a href="https://egghead.io/courses/build-your-first-production-quality-react-app">“ Build Your First Production Quality React App”</a></li><li>Alex Lobera’s Medium article <a href="https://medium.com/leanjs/universal-create-react-app-step-by-step-b80ba68d125d">“Universal create-react-app, step by step”</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f819bbdeb624" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>