<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrew McKeever</title>
    <description>The latest articles on DEV Community by Andrew McKeever (@keevcodes).</description>
    <link>https://dev.to/keevcodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F125813%2F158fcd67-da1a-4a91-ba9f-db1fdbde817b.jpg</url>
      <title>DEV Community: Andrew McKeever</title>
      <link>https://dev.to/keevcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/keevcodes"/>
    <language>en</language>
    <item>
      <title>Cleaner short circuits with optional chaining.</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Mon, 23 Mar 2020 17:06:15 +0000</pubDate>
      <link>https://dev.to/keevcodes/cleaner-short-circuits-with-optional-chaining-50b3</link>
      <guid>https://dev.to/keevcodes/cleaner-short-circuits-with-optional-chaining-50b3</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Support for the optional chaining operator came to some major browser releases, allowing for easier and cleaner retrieval of nested object methods and properties given that they exist.* &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  What is Optional Chaining(?.)
&lt;/h1&gt;

&lt;p&gt;One of the most common operations that us developers need to perform on objects is retrieving its properties and methods. Many times these properties/methods contain other properties/methods that we have to drill down to. However, not every object will have said properties/methods and we end up breaking our code. A common way to handle these errors is to use the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator when drilling down the object, creating a short circuit if the property is returns &lt;code&gt;undefined&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Boat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Boaty&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;last&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;McBoatface&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
   &lt;span class="p"&gt;},&lt;/span&gt;
   &lt;span class="na"&gt;cargo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;// additional props could reside here&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/** 
  * check if boat has cargo 
  * then an item 
  * then return the quantity of item
  */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;boatQuantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
  &lt;span class="nx"&gt;boat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cargo&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; 
  &lt;span class="nx"&gt;boat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cargo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; 
  &lt;span class="nx"&gt;boat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cargo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quantity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can see that even trying to go only a couple layers deep into an object with the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator things are getting a little messy. However, the optional chaining operator cleans up our code a lot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// such clean, much readability&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;boatQuantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;boat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cargo&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Support
&lt;/h1&gt;

&lt;p&gt;Outside of Safari, the latest version of all major browsers now support the optional chaining operator. Alongside them, Babel also provides support so if you're already using Babel in your projects, upgrade to 7.8.3 (maybe earlier? this was the earliest release I could find) and you're good to go. &lt;/p&gt;

&lt;p&gt;Thanks for reading! Stay safe and healthy out there everyone&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A use case for the Object.entries() method</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Wed, 05 Feb 2020 07:15:03 +0000</pubDate>
      <link>https://dev.to/keevcodes/a-use-case-for-the-object-entries-method-5dcj</link>
      <guid>https://dev.to/keevcodes/a-use-case-for-the-object-entries-method-5dcj</guid>
      <description>&lt;p&gt;&lt;em&gt;Perhaps you already know about Object.keys() and Object.values() to create an array of an objects keys and values respectively. However, there's another method &lt;code&gt;Object.entries()&lt;/code&gt; that will return a nested array of the objects key and values. This can be very helpful if you'd like to return only one of these pairs based on the other's value.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  A clean way to return keys in an Object
&lt;/h1&gt;

&lt;p&gt;Often times in form with form data there will be a list of choices presented to users that are selectable with radio buttons. The object's data returned from this will look something like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myListValues&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;selectionTitle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;anotherSelectionTitle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We could store these objects with their keys and value in our database as they are, however just adding the &lt;code&gt;key&lt;/code&gt; name for any truthy value would be sufficient. By passing our &lt;code&gt;myListValues&lt;/code&gt; object into Object.entries() we can filter out any falsey values from our newly created array and then&lt;br&gt;
return the keys as a string. &lt;/p&gt;
&lt;h3&gt;
  
  
  Execution
&lt;/h3&gt;

&lt;p&gt;We'll make use of not only Object.entries(), but also the very handy array methods &lt;code&gt;filter()&lt;/code&gt; and &lt;code&gt;map()&lt;/code&gt;. The output from &lt;code&gt;Object.entries(myListValues)&lt;/code&gt; will be...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;separatedList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;selectionTitle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;],&lt;/span&gt; 
   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;anotherSelectionTitle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
 &lt;span class="p"&gt;];&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now have an array that can be utilise &lt;code&gt;.filter()&lt;/code&gt; and &lt;code&gt;.map()&lt;/code&gt; to return our desired result. So let's clean up our &lt;code&gt;separatedList&lt;/code&gt; array a bit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;separatedFilteredList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
   &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myListValues&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;selectedItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;separatedFilteredList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There we have it. Our selectedItems array is now just a list of the key names from our objects who's value was truthy. This is just one of many use cases for perhaps a lesser know object method. I'd love to see some more interesting use cases you may have come up with. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Using CSS modules</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Wed, 15 Jan 2020 14:30:33 +0000</pubDate>
      <link>https://dev.to/keevcodes/using-css-modules-to-style-components-3f01</link>
      <guid>https://dev.to/keevcodes/using-css-modules-to-style-components-3f01</guid>
      <description>&lt;p&gt;&lt;em&gt;Breaking larger code bases into smaller chunks using component based architecture has made it much easier for us developers to architect a clean project; it can even improve productivity. However, one of the biggest challenges in creating unique names for all of these components, since many of them tend to function similarly or are the same type with a few style modifiers. This overlap can cause a huge mess in our CSS. The popular solution to this problem has been to use CSS in JS and many libraries have been built each with their own take on how to do it. However, plain CSS offers a solution with a simple amount of configuration, allowing us to avoid depending on a library.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Why use CSS Modules?
&lt;/h1&gt;

&lt;p&gt;The main benefit of CSS modules is that classes are locally scoped. Every classname generated in a CSS file will have a unique name given to it at build time. How is this handled? Well we will need to set up Webpack to do this for us, but don't worry it's not too bad. &lt;/p&gt;

&lt;p&gt;If you're used to using naming conventions like BEM to prevent class styling overlap, you'll know that classnames can become incredibly long. This makes it harder to read your code and really know which styles am element is receiving from which modifiers. With CSS modules, you can drop naming conventions as you only have to worry about unique names inside of the locally scoped file(e.g. two elements in separate JS and CSS files can have the same name). &lt;/p&gt;

&lt;h1&gt;
  
  
  How to get started.
&lt;/h1&gt;

&lt;p&gt;Getting started doesn't require too much setting up, but can be a little confusing if you're unfamiliar with Webpack. However, even if you've got very little experience it's one of the easier configurations to get working. We'll need to install the &lt;code&gt;css-loader&lt;/code&gt; package from &lt;code&gt;npm&lt;/code&gt; to use it in our &lt;code&gt;webpack.config&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;css$/i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we're telling Webpack to use &lt;code&gt;css-loader&lt;/code&gt; to handle all files with the CSS extension. From there we just set the module option to true and that's it! Pretty straight forward. &lt;/p&gt;

&lt;p&gt;Once we've configured Webpack we're ready to get started. We can create our style sheet like we normally would; we'll create a styles.css for this example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;
  &lt;span class="nc"&gt;.someComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ebebeb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we import simply import our style sheet into our JS file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;


&lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHtml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;div class={style.someComponent}&amp;gt;I'm using CSS modules&amp;gt;&amp;lt;/div&amp;gt;`&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As mentioned, CSS modules will become locally scoped. Our output then at build time will look something similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;html

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"style_someComponent__3N3nB"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I'm using CSS modules&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;css&lt;/span&gt;

  &lt;span class="nc"&gt;.style_someComponent__3N3nB&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ebebeb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all there is to it! We can now easily prevent any stylings from overriding components where they shouldn't without changing much at all on how we style our html. &lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Happy New Year!</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Tue, 31 Dec 2019 05:37:31 +0000</pubDate>
      <link>https://dev.to/keevcodes/happy-new-year-1ncp</link>
      <guid>https://dev.to/keevcodes/happy-new-year-1ncp</guid>
      <description>&lt;p&gt;Happy New Year 🎉 to everyone in this awesome Dev.to community, It's been a great alternative to other blog platforms. I also would like to thank everyone for reading and following me this year. When I started I had a goal of reaching 500 followers at the year's end; I've now reached 2800 followers! Thank you all for taking interest in my writing and being a wonderful community. I hope everyone has been relaxing and enjoying time with families and loved ones this past week.&lt;/p&gt;

&lt;p&gt;See you all in 2020! 🥳&lt;/p&gt;

</description>
      <category>community</category>
      <category>gratitude</category>
    </item>
    <item>
      <title>Beef up your HTTPS sites with a Content Security Policy</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Fri, 13 Dec 2019 08:22:42 +0000</pubDate>
      <link>https://dev.to/keevcodes/beef-up-your-https-sites-with-a-content-security-policy-5edn</link>
      <guid>https://dev.to/keevcodes/beef-up-your-https-sites-with-a-content-security-policy-5edn</guid>
      <description>&lt;p&gt;&lt;em&gt;HTTPS is quickly becoming a standard implementation when creating a website or application. Most hosting platforms make it rather simple to host our sites over HTTPS. Github pages even makes it totally free and as simple as a button click. However, without setting up a strict Content Security Policy, you're still leaving your sites vulnerable. Content Security Policies aren't exactly a 'sexy' part of development to learn though and strict ones can break your site. The goal of this article is to help clarify some common issues you may run across when setting up a CSP.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;A Content Security Policy (CSP) is a HTTP header, built for protecting against various site attacks, mainly cross site scripting attacks (XXS). A good CSP is strict as possible, only allowing external JS and CSS scripts from third parties that are needed to run the site. Another good (pretty much essential) practice is to provide a nonce tag or an sha based hash for any inlined JavaScript (I'll explain how to do this a bit later). &lt;/p&gt;

&lt;p&gt;All this blocking can quickly become a serious issue however, since any script not listed in a CSP will be blocked and if this particular script is essential to run the site (e.g. a runtime script for a JS library) it'll break the whole page. Testing a CSP on a staging environment before implementing it on production is a must. &lt;/p&gt;

&lt;h1&gt;
  
  
  How to implement
&lt;/h1&gt;

&lt;p&gt;There are a couple ways to implement a CSP, one is by directly adding it in the meta tag of your &lt;code&gt;index.html&lt;/code&gt;, the other is via server side. Directly adding it to the meta tag is quite convenient, especially for statically hosted sites and/or you only have a few external scripts tags you need allow in the CSP. However, server side gives you the added benefit of being able to dynamically add scripts as you need them and can create allow you to create an extra layer or security. &lt;/p&gt;

&lt;p&gt;No matter which direction you choose, there will be a few directives you'll need to consider when adding your scripts. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;default-src&lt;/code&gt;: As the name implies, this is the default fall back for any directives that aren't applied in your CSP. A common source for this would be 'self', which would allow only scripts that come from the origin. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;script-src&lt;/code&gt;: This directive defines what sources are allowed to include their JS. Defining these is one of the more crucial directives to protect your site, but keep in mind this is also the one that will cause the most breaks if not set correctly. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;style-src&lt;/code&gt;: CSS style sheets from different sources. If there's any library that requires to embed their own CSS then include them here, but 'self' is again a standard choice. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;font-src&lt;/code&gt;: Using google fonts or other font sources? You'll want to add these here. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;frame-src&lt;/code&gt;: This directive is for those sources that will embed iFrames into your page. Stripe or Google Maps come to mind here. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are a host of others out there available, just be sure to check the browser support for them. You can find more from the &lt;a href="'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy'"&gt;Mozilla Docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There's one more thing, the &lt;code&gt;unsafe-inline&lt;/code&gt; value. You can set this value to allow any source to set inlined resources, like JS or CSS. This may prevent your site from breaking, like an inline React runtime, but this is leaving your site almost as vulnerable as it was without setting up a CSP. Avoid this as much as you can. &lt;/p&gt;

&lt;h1&gt;
  
  
  Avoid unsafe-inline with hashing
&lt;/h1&gt;

&lt;p&gt;The point of only granting certain sites the ability to add their scripts is to protect you from outsiders wanting to sneak malicious code into your code. The &lt;code&gt;unsafe-inline&lt;/code&gt; rule allows any third party to add inlined JS directly into a script tag. To get full advantage of a CSP you'll need to avoid this property by using either a &lt;code&gt;nonce&lt;/code&gt; or a generated hash following at least the &lt;code&gt;sha256&lt;/code&gt; algorithm.  &lt;/p&gt;

&lt;p&gt;You may have noticed by now, if you've tried setting any of the &lt;code&gt;script-src&lt;/code&gt; or &lt;code&gt;frame-src&lt;/code&gt; directives that Chrome (assuming you use it) may have generated a hash for you, This is possibly the easiest and most straightforward way to add a hash. However, Chrome may not do this for every script or style attribute that is being inlined.&lt;/p&gt;

&lt;p&gt;Another popular way is to use Node.js or a backend language to generate them for you and then add them to the CSP dynamically. If you're server-side rendering (SSR) then doing this shouldn't be too difficult. There are some libraries out there to help you generate a hash or nonce; Node.js has &lt;code&gt;crypto&lt;/code&gt; for example. If you're using AWS to host a static site with CloudFront, then you could use a Lambda function installed with Node or Python to do something similar. I'm unsure of other serverless services, but they may also have something comparable.  &lt;/p&gt;

</description>
      <category>programming</category>
      <category>security</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Syncing up Google Ads and Analytics to your React App.</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Thu, 05 Dec 2019 05:23:37 +0000</pubDate>
      <link>https://dev.to/keevcodes/syncing-up-google-ads-and-analytics-to-your-react-app-516o</link>
      <guid>https://dev.to/keevcodes/syncing-up-google-ads-and-analytics-to-your-react-app-516o</guid>
      <description>&lt;h1&gt;
  
  
  Getting setup
&lt;/h1&gt;

&lt;p&gt;Google has made it quite simple to integrate Ads and Analytics. To get started you'll need an account for both services. You'll need to obviously enter in personal info, leaving that feeling like you're selling your soul to the devil. For Analytics you'll also need the URL of your site. Once you're setup head over to Analytics then proceed to &lt;em&gt;admin -&amp;gt; property -&amp;gt; tracking info -&amp;gt; tracking code&lt;/em&gt; to fetch your trackingID. Keep the trackingID handy as you'll need it later in our App.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;your trackingId should look something like&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;UA-XXXXXXX-X&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We'll also need to to setup a GoogleAds account. Follow Google's setup process of creating an account and choosing a plan (more soul selling). Once you've gone through the initial setup, we'll want to link our Ads account to our Analytics Account. On the Ads dashboard, select the &lt;em&gt;tools -&amp;gt; setup -&amp;gt; linked accounts&lt;/em&gt;. Select details and you should be prompted to add in the trackingID you grabbed from Analytics. Thats pretty much all there is to it. &lt;/p&gt;

&lt;h1&gt;
  
  
  Creating and using an event
&lt;/h1&gt;

&lt;p&gt;React-ga is a package built off the Analytics API offering a variety of config options making it a breeze to implement Analytics in our App. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn install react-ga&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once installed we'll need to import react-ga inside of the main page where our app is built (App.js or Index.js). Then we'll pass it our Analytics trackingId we got earlier during setup, react-ga will handle all the boilerplate code needed in our app. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;ReactGA.initialize('UA-XXXXXXX-X')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This next part is left up to you. Where ever in your code you'd like to place GoogleAds, you'll need to create a new Analytics event using &lt;code&gt;ReactGA.event&lt;/code&gt;. No matter where you place your event, there are a few parameters that are important to remember because you'll need to set them exactly the same in Analytics. The event will look something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
  &lt;span class="nx"&gt;ReactGA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some category&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example_action&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example label&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are some configurations you can add to the event object, but these three are the important ones. Once this is done, head on back over to GoogleAnalytics and back under the admin page, find &lt;strong&gt;Goals&lt;/strong&gt; and select &lt;strong&gt;Create A New Goal&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;You'll want to create a new custom goal in the initial setup and then provide a description and select &lt;strong&gt;Event&lt;/strong&gt; for the type. Now, under goal details place fill in &lt;em&gt;Category&lt;/em&gt;, &lt;em&gt;Action&lt;/em&gt; and &lt;em&gt;Label&lt;/em&gt; exactly as you did before in the ReactGA.event(). Once you're done save your event. &lt;/p&gt;

&lt;h1&gt;
  
  
  Tying it all together.
&lt;/h1&gt;

&lt;p&gt;Head on over to your GoogleAds dashboard and under &lt;em&gt;Tools &amp;amp; Settings&lt;/em&gt; select &lt;em&gt;conversions&lt;/em&gt;. There'll be a nice blue + sign in the upper left corner to add a new conversion, give it a click and then select &lt;em&gt;import&lt;/em&gt;. By syncing our Ads and Analytics accounts up earlier, we're now able to import our newly created goal in Analytics as a conversion in Ads and BOOM! we're all set. Any Ad campaigns you've set up for the conversion should now be tracked in Google Ads. &lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Agencies or In-house, which do you prefer?</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Wed, 27 Nov 2019 09:37:16 +0000</pubDate>
      <link>https://dev.to/keevcodes/agencies-or-in-house-which-do-you-prefer-72a</link>
      <guid>https://dev.to/keevcodes/agencies-or-in-house-which-do-you-prefer-72a</guid>
      <description>&lt;p&gt;I spent my first few years of as a developer working for agencies, but recently moved to an in-house company.&lt;/p&gt;

&lt;p&gt;Since each project usually has a short deadline, agencies give you the option of changing up the tech stack, which is great for learning. The main differences I've noticed so far...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Testing is a larger concern for in-house. Outside of VC pressure, there's not as tight of deadlines in-house compared to agency projects. However, because we're not handing-off the project(s) to clients, maintenance is also a larger responsibility. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;More discussions happen before a solution is decided on when working in-house.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implementing hot-fixes and coming back to them later is possible in-house. This option isn't really there when you're going to be handing your code off for someone else to maintain. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Which do you prefer? What are some differences you've noticed between the two?  &lt;/p&gt;

</description>
      <category>watercoolerdiscuss</category>
    </item>
    <item>
      <title>More time coding, less time debugging. Interfaces in TypeScript applications</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Mon, 18 Nov 2019 03:29:11 +0000</pubDate>
      <link>https://dev.to/keevcodes/more-time-coding-less-time-debugging-interfaces-in-javascript-applications-31f7</link>
      <guid>https://dev.to/keevcodes/more-time-coding-less-time-debugging-interfaces-in-javascript-applications-31f7</guid>
      <description>&lt;p&gt;&lt;em&gt;The goal of this article is to deepen your understanding of what interfaces are, not just how to build them. Building a solid foundation of programming concepts will strengthen you as a developer, better preparing you for interviews and your career&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you've happened to come across an application written in  Typescript you've probably ran across something like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;hairColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We call this an interface and they're great because they allow us to define the structure of our objects an input, preventing unwanted properties or methods from creeping into our data. Interfaces do this by checking that the input our code is receiving adheres to the data types we've set inside the interface. This helps our applications to run as expected. &lt;/p&gt;

&lt;p&gt;However, if you're like me and never really worked with a strict data types, like those found in Java or C#, programming to interfaces can present a challenge. After all, dynamic languages (duck typing) like JavaScript don't require us to declare data types, which makes them easy to learn. So if programming to strictly typed interfaces can be difficult, why use them at all? Let's explore this idea. &lt;/p&gt;

&lt;h1&gt;
  
  
  Where do interfaces come from?
&lt;/h1&gt;

&lt;p&gt;Now, while I think it's pretty important to understand the full reasoning behind programming to interfaces, I will briefly summarise it as a) there's a lot to cover, which would it's own post and b) many a greater developers than myself have written said as articles on this very thing. In a nutshell, the language we write in is a set of instructions for our computer to run our applications. These instructions can only be handled between 4 or 8 bytes at a time so declaring which data types are in our code before its compiled does some of the leg work already, allowing the computer optimally perform. &lt;/p&gt;

&lt;p&gt;Concatenating two different data types, a string and a number for example, make it more work for our computer; especially if these different data types were actually meant to be of the same type. By declaring our data types as we code, we cut down on the amount of time it takes our computer to read our instructions. This is why strictly typed languages exist. &lt;/p&gt;

&lt;h1&gt;
  
  
  Why should I use interfaces?
&lt;/h1&gt;

&lt;p&gt;Spending time debugging code or trying solve issues QA has found in your code can be a major headache. For me, the only thing worse than being stuck on a problem, is having a feeling of relief finishing a new feature, only to have to go back and fix a load of bugs in said feature.&lt;br&gt;
If you're in an environment using sprints, the time spent debugging isn't usually considered in the initial estimation to develop said feature. Structuring your code around interfaces will take more time, but that's more time coding allowing you and your team to better estimate new features in the sprint plan. &lt;/p&gt;

&lt;h1&gt;
  
  
  So I should always use interfaces then?
&lt;/h1&gt;

&lt;p&gt;No, like any language or framework, there's a time and a place for strict typing with JavaScript. If you're working on a smaller project with a two month deadline and no backend, then strict typing will probably just slow you down. While projects like these wont be bug free, unless you've added maintenance into the budget, time isn't on your side here. &lt;br&gt;
However, less time fixing bugs means more time implementing new features so ultimately consider how much time you have vs. how long you think it'll take to yourself and you team to become productive with strict types. &lt;/p&gt;

&lt;p&gt;Personal preference is another consideration although you can't build a preference without first trying the alternative. I'll admit that I get frustrated programming to interfaces (this was especially true early on), but they're growing on me the more I use them. Still, strict typing isn't for everyone just like dynamic typing isn't either and that's totally fine. Multiple languages exist for a reason, but I've you haven't tried strict typing yet, I recommend giving it a chance. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>typescript</category>
    </item>
    <item>
      <title>VScode extensions and shortcuts to improve your productivity</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Mon, 11 Nov 2019 05:12:55 +0000</pubDate>
      <link>https://dev.to/keevcodes/vscode-extensions-and-shortcuts-to-improve-your-productivity-2m3a</link>
      <guid>https://dev.to/keevcodes/vscode-extensions-and-shortcuts-to-improve-your-productivity-2m3a</guid>
      <description>&lt;p&gt;Since I started using VSCode a couple of years ago, I've learned quite a few handy shortcuts and installed some incredible extensions to make my day to day not only easier, but also quicker and more productive. Perhaps many of you are familiar already with some of these, but I hope to introduce you to some new ones too!&lt;/p&gt;

&lt;h1&gt;
  
  
  Shortcuts
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;⌘ K ⌘ C&lt;/code&gt;: This command is by far my favorite one I've learned. It's used to add comment lines, but it can also be used to comment out lines if you're wanting to quickly test a piece of code. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;⌘X&lt;/code&gt;: Cut away a whole line of code. It'll get saved into your clipboard allowing you to either delete or paste it somewhere else with  &lt;code&gt;⌘V&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;⌥⌘↑&lt;/code&gt;: Multi-cursors are great for editing, removing or commenting multiple lines of code at the same time. Using the &lt;code&gt;↑&lt;/code&gt; or &lt;code&gt;↓&lt;/code&gt; directional keys will add a cursor to a line above or below respectively. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;⇧⌘L&lt;/code&gt;: Select all occurrences of selected piece of code. This comes in really handy for changing variable names. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Extensions
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager"&gt;Project Manager&lt;/a&gt;: So much of my day is switching between repositories wether thats due to bugs in one project causing problems in another or implementing many features in one day. This extension allows you to save projects and easily switch between them via &lt;code&gt;⌘⌥P&lt;/code&gt; shortcut. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=Atlassian.atlascode"&gt;Jira and Bitbucket Extension&lt;/a&gt;: For the many of use who are using Jira boards to handle ticketing our issues or features, this extension allows you to create and modify Jira tickets directly in your editor. It will even give you the option to create a ticket directly from a &lt;code&gt;/**TODO:**/&lt;/code&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments"&gt;Better Comments&lt;/a&gt;: Speaking of writing TODOs, Better Comments provides syntax highlighting and comment formatting to make your life and the lives of other developers who read your code easier. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer"&gt;Bracket Pairing&lt;/a&gt;: When I first started learning to program I would easily get lost trying to figure out which brackets were closed and which were open, let alone trying to figure out which one I actually need to delete. Nested brackets in any code base can be a pain to navigate through without a colorizer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=shyykoserhiy.vscode-spotify"&gt;VSCode-Spotify&lt;/a&gt;: I'm not sure about your office, but mine tends to be pretty damn quiet with all of us developers hacking away behind the computer. I couldn't get through my day without listening to music or podcasts. This handy little extension connects the Spotify application to VSCode, creating a handy toolbar to skip, pause and play songs or podcasts directly in the editor. Really nice if you just need to quickly pause to ask or answer a question. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;I hope I introduced you to some new shortcuts or extensions, feel free to comment down below some of your favorites!&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>vscode</category>
    </item>
    <item>
      <title>What's some of your favorite experiences with onboarding?</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Mon, 04 Nov 2019 21:05:03 +0000</pubDate>
      <link>https://dev.to/keevcodes/what-s-some-of-your-favorite-experiences-with-onboarding-5bdl</link>
      <guid>https://dev.to/keevcodes/what-s-some-of-your-favorite-experiences-with-onboarding-5bdl</guid>
      <description>&lt;p&gt;Today was my first day at a new company and after a briefing on the company history along a partner to help guide me with their workflow, I was also given a detailed list of what needed to be setup. While this might not seem like much, previous companies never did something as detailed as this. What have been some of your best experiences with onboarding? &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Improve accessibility with prefers-reduced-motion</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Mon, 28 Oct 2019 12:42:35 +0000</pubDate>
      <link>https://dev.to/keevcodes/improve-accessibility-with-prefers-reduced-motion-54i6</link>
      <guid>https://dev.to/keevcodes/improve-accessibility-with-prefers-reduced-motion-54i6</guid>
      <description>&lt;p&gt;&lt;em&gt;Making our sites or apps accessible is a major responsibility for all of us developers. Many of us know about adding descriptive alt tags to images or choosing the appropriate color contrast for text with a background, however there are a few out there you may not know about including prefers-reduced-motion.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One of the biggest joys in front-end development is getting the opportunity to implement really cool animations. Many hours can be spent working alongside designers tweaking a cubic-bezier to make that fade out scrolling animation just right. A well thought out animation can take your site from something simple and bland to lively and interactive. However, not every user enjoys them. Some might be very sensitive to too much motion causing them to feel ill. Fortunately it's become trivial to help these users out by adding a simple CSS property, &lt;code&gt;prefers-reduced-motion&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  What it does
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Prefers-reduced-motion&lt;/code&gt; attempts to stop any non essential animations from being triggered when a user specifies so. For example, any fading or sliding animations that are triggered when a user scrolls for an interactive feel, but not essential to the actual site should be left out at the user's request. &lt;/p&gt;

&lt;h1&gt;
  
  
  How to work with it.
&lt;/h1&gt;

&lt;p&gt;Nearly all of us web developers have used media queries in some fashion or another and &lt;code&gt;prefers-reduced-motion&lt;/code&gt; is as simple to implement as a media query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.myAnimation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3s&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt; &lt;span class="n"&gt;bounce&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-reduced-motion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.myAnimation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it to disable any animations you feel aren't essential to the user experience, giving relief to those who may be susceptible to motions. What is essential is left up to you and the designer. Animations that give users feedback like button clicks or successful form submissions would probably be considered essential, but most could be considered unessential. We can also slow animations down or decrease their frequency instead of disabling them all together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Browser Support
&lt;/h3&gt;

&lt;p&gt;In terms of &lt;a href="https://caniuse.com/#search=prefers-reduced-motion"&gt;browser support&lt;/a&gt;, the latest two versions of Chrome, Firefox and Safari all support &lt;code&gt;prefers-reduced-motion&lt;/code&gt;. The latest Edge also supports it, however IE11 doesn't. &lt;/p&gt;

</description>
      <category>a11y</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A quick glimpse into Server side rendering a React App</title>
      <dc:creator>Andrew McKeever</dc:creator>
      <pubDate>Thu, 17 Oct 2019 15:52:43 +0000</pubDate>
      <link>https://dev.to/keevcodes/a-quick-glimpse-into-server-side-rendering-a-react-app-3420</link>
      <guid>https://dev.to/keevcodes/a-quick-glimpse-into-server-side-rendering-a-react-app-3420</guid>
      <description>&lt;p&gt;&lt;em&gt;Server side rendering took a bit of a back seat with the initial popularity boom of client side frameworks. On the other hand, SPAs create a challenge with SEO since many web crawlers aren't capable of crawling client side JS bundles. However, SSR is making a comeback with the ease of implementing our beloved client side frameworks on the server. This gives us some nice advantages while still utilizing the performance power from a client side framework. In the this article I'd like to take a brief look into server side rendering a React App.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Why use SSR
&lt;/h1&gt;

&lt;p&gt;There really are two main advantages of server-side rendering &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Better SEO &lt;/li&gt;
&lt;li&gt;Faster initial page loads&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With a client-side application, we're only generating a small HTML file with basically zero content outside of a script tag with something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text/javascript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes it pretty difficult for web crawlers to read what kind of content is on our site, killing our SEO. By generating our React components as HTML files on the server, we avoid this problem.&lt;/p&gt;

&lt;p&gt;Browsers load HTML, CSS then the JS of our web pages and Apps. If all the content of our SPA written is inside our React components users won't see any content until after our CSS and JS is fully loaded. By handling our JSX content as HTML markup on the server our SPA's initial load time will be much faster. There is a downside to this though, which I'll explain a bit later. &lt;/p&gt;

&lt;h1&gt;
  
  
  A bit on how it works
&lt;/h1&gt;

&lt;p&gt;I'm going to make the assumption that you're familiar with setting up an Express server with Node.js as going through that setup is beyond the scope of this article. If you've never setup an Express server before, have a look at this &lt;a href="https://expressjs.com/en/starter/hello-world.html"&gt;Express&lt;/a&gt; example. To get your React SPA from client to server side you'll follow the basic Express app setup. Our server will also need React the &lt;code&gt;ReactDOMServer&lt;/code&gt; object to convert our component to markup. This object comes with a few important methods, one in particular.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;ReactDOMServer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someComponent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;renderToString()&lt;/code&gt; method accepts a React component and converts it to our HTML markup, allowing crawlers to work their magic. On the client side, our components don't change much in terms of their regular syntax, however instead of &lt;code&gt;ReactDom.render()&lt;/code&gt; we must now use &lt;code&gt;ReactDOM.hydrate()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Reading the initial documentation on &lt;a href="https://reactjs.org/docs/react-dom.html#hydrate"&gt;hydrate&lt;/a&gt; feels slightly more complex than it actually is. When we send an HTML file to the client via server side, we're sending static content along with it. However, we know that with a React app, that many of our components will need to be updated with state changes. Handling these state changes by generating our HTML on the server, sending it to the client, client making a request for an update to the server and then the server sending back the updated HTML is time consuming (why we have client side frameworks in the first place). &lt;/p&gt;

&lt;p&gt;We can however, send a static version of our App as an HTML string to the client. This "dehydrated" version will then receive event listeners to any DOM nodes we specify in our react components which can then be referenced for changes in our applications state, similar to any other client-side only React App you may have created in the past. &lt;/p&gt;

&lt;h1&gt;
  
  
  Caveats
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Setup for React Apps via SSR are quite complex. Webpack configurations need to be set up for JS bundles, like any application from scratch setup, however servers also can't read JSX which requires more configuring. Thankfully, frameworks like Next.js and Gatsby have emerged to make this setup easier. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SSR can help speed up first paint, but time to interactive can cause users to be deceived since only our static content is loaded on the server side, but our bundled JS still needs to load. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Thanks for reading this very brief introduction into how server side rendering works with a React application. As always comments, questions and constructive criticisms are always welcomed.&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
