<?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>Forem: Cristofer</title>
    <description>The latest articles on Forem by Cristofer (@christo_pr).</description>
    <link>https://forem.com/christo_pr</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%2F73435%2F03e68a2a-bf8f-48cf-8b62-b78798e845e1.png</url>
      <title>Forem: Cristofer</title>
      <link>https://forem.com/christo_pr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/christo_pr"/>
    <language>en</language>
    <item>
      <title>Create a nice-looking input range with only CSS!!</title>
      <dc:creator>Cristofer</dc:creator>
      <pubDate>Wed, 29 Apr 2020 17:52:59 +0000</pubDate>
      <link>https://forem.com/christo_pr/create-a-nice-looking-input-range-with-only-css-4oa2</link>
      <guid>https://forem.com/christo_pr/create-a-nice-looking-input-range-with-only-css-4oa2</guid>
      <description>&lt;p&gt;We all as a developers know the importance of the &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt; tag element, without it, we wouldn't have a way to receive any input from the user.&lt;/p&gt;

&lt;p&gt;There are a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#&amp;lt;input&amp;gt;_types" rel="noopener noreferrer"&gt;lot of types&lt;/a&gt; that we can use on an &lt;code&gt;input&lt;/code&gt; element, and each one, change the behavior of the element, here's a list of the most common types of input's:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;text&lt;/strong&gt;: The default value. A single-line text field.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fskvpljjodgpvhcrgqto7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fskvpljjodgpvhcrgqto7.png" alt="text input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;button&lt;/strong&gt;: A push button with no default behavior displaying the value of the value attribute, empty by default. If it's inside a &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; tag, it will submit the form when pressed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fca9jhisayhscohi3ybv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fca9jhisayhscohi3ybv3.png" alt="button input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;checkbox&lt;/strong&gt;: A check box allowing single values to be selected/deselected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F50k2xl5h7lsm7452u0pj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F50k2xl5h7lsm7452u0pj.png" alt="checkbox input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;color&lt;/strong&gt;: A control for specifying a color; opening a color picker when active in supporting browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fecejrvgjtbffl9jxnq2f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fecejrvgjtbffl9jxnq2f.png" alt="color input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;email&lt;/strong&gt;: A field for editing an email address. Looks like a &lt;strong&gt;text&lt;/strong&gt; input, but with validation parameters on supported devices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwlgtvcng2qdsb5hra3bt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwlgtvcng2qdsb5hra3bt.png" alt="email input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;password&lt;/strong&gt;: A single-line text field whose value is obscured. Will alert user if site is not secure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmfcq7pb2ng8ejzuwcyty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmfcq7pb2ng8ejzuwcyty.png" alt="pass input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;number&lt;/strong&gt;: A control for entering a number. Displays a spinner and adds default validation when supported.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9ddq14t0hmq0h979vt6v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9ddq14t0hmq0h979vt6v.png" alt="number input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;hidden&lt;/strong&gt;: A control that is not displayed but whose value is submitted to the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;center&gt; *No image for obvious reason xD* &lt;/center&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;range&lt;/strong&gt;: A control for entering a number whose exact value is not important. Displays as a range widget defaulting to the middle value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6qiduilk2tm2775e6q97.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6qiduilk2tm2775e6q97.png" alt="range input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, there are a lot of types that we can use, you can check them in deep &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  &lt;code&gt;&amp;lt;input type="range" /&amp;gt;&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;In this post I'm going to show you how to modify the default style for the  &lt;strong&gt;range input type&lt;/strong&gt; so it looks better.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; All the code below works &lt;strong&gt;only&lt;/strong&gt; on Chrome and Opera, TBH I didn't even try to fix any visual bug on any other browser.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The very basic implementation of an input range looks like this:&lt;/p&gt;

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

&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"range"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This will render the same as the saw above:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6qiduilk2tm2775e6q97.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6qiduilk2tm2775e6q97.png" alt="range input type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have available some extra properties when using this element:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;value&lt;/code&gt;: String representation of a number, although it can't be an empty string (&lt;code&gt;""&lt;/code&gt;). The default value is always halfway between &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt; properties. This is how is calculated:&lt;/li&gt;
&lt;/ul&gt;

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

&lt;span class="nx"&gt;defaultValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rangeElem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;rangeElem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;rangeElem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;
               &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;rangeElem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rangeElem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;rangeElem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;max&lt;/code&gt; &amp;amp; &lt;code&gt;min&lt;/code&gt;: The maximum and minimum value permitted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;step&lt;/code&gt;: The stepping interval.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;list&lt;/code&gt;: The id of the &lt;code&gt;&amp;lt;datalist&amp;gt;&lt;/code&gt; element that contains optional pre-defined options.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok! enough with HTML Input 101, let's put a style on that input!.&lt;/p&gt;

&lt;p&gt;First we need the basic html structure, something like this:&lt;/p&gt;

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

&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;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;datalist&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"custom-list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"6"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"7"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"9"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"11"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/datalist&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"range"&lt;/span&gt; &lt;span class="na"&gt;min=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; &lt;span class="na"&gt;max=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt; &lt;span class="na"&gt;step=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; &lt;span class="na"&gt;list=&lt;/span&gt;&lt;span class="s"&gt;"custom-list"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;The markup above will render this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvbkf6d80amavy0irqb8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvbkf6d80amavy0irqb8j.png" alt="input with datalist"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It renders a &lt;strong&gt;hash mark&lt;/strong&gt; for each &lt;code&gt;&amp;lt;option&amp;gt;&lt;/code&gt; of the &lt;code&gt;&amp;lt;datalist&amp;gt;&lt;/code&gt; element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thumb and tracker
&lt;/h2&gt;

&lt;p&gt;On any slider control, we have 2 element that we can interact to, the &lt;em&gt;thumb&lt;/em&gt; and the &lt;em&gt;tracker&lt;/em&gt;, the thumb is just the little widget that let you drag and drop along the track:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcr46bblgkifzj9cils1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcr46bblgkifzj9cils1u.png" alt="thumb &amp;amp; track"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They're called &lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM" rel="noopener noreferrer"&gt;Shadow DOM elements&lt;/a&gt;&lt;/strong&gt; and we can actually style them with CSS, so let's start by that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enable user agent shadow DOM
&lt;/h2&gt;

&lt;p&gt;I recommend you to enable the Shadow DOM on your browser, since we can't inspect this elements by default, and sometimes it's easier to just manipulate the element directly from the developer tools instead of the common process: change, save &amp;amp; reload.&lt;/p&gt;

&lt;p&gt;I'll show you how to activate it using Opera, but this works the same on Chrome, and I'm pretty sure that on FF it's just as easy as it is on Opera (is just a checkbox, shouldn't be a big issue on any browser).&lt;/p&gt;

&lt;p&gt;So, first open the Developer Tools (&lt;strong&gt;F12&lt;/strong&gt;) in your browser, once its open, either press &lt;strong&gt;F1&lt;/strong&gt; or use the kebab menu (A.K.A 3 dots menu) and click on the "&lt;em&gt;settings&lt;/em&gt;" option:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1f29154tup7c173x3vus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1f29154tup7c173x3vus.png" alt="settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will open the settings section. Next, we only need to check the option "&lt;em&gt;Show user agent shadow DOM&lt;/em&gt;" under the &lt;strong&gt;Elements&lt;/strong&gt; list:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5bdahmnv9uk8pxs3aisx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5bdahmnv9uk8pxs3aisx.png" alt="activate shadow dom"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, if we inspect the input, instead of looking like a regular input element:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flsqaac1me3ful00vxq4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flsqaac1me3ful00vxq4a.png" alt="regular input range"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll see the markup a bit different:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6t5i64rd3dfzccpr915l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6t5i64rd3dfzccpr915l.png" alt="input range shadow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The input has elements inside, which represent the tracker and the thumb, now will be easier to inspect and modify the styles for this elements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Styling
&lt;/h3&gt;

&lt;p&gt;Let's start by styling our container element and removing the default look &amp;amp; feel of the input&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;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;450px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"range"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;-webkit-appearance&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="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="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;To style the thumb and the tracker we have the &lt;strong&gt;pseudo-elements&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;::-webkit-slider-runnable-track&lt;/code&gt;: Selector for the tracker.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;::-webkit-slider-thumb&lt;/code&gt;: Selector for the thumb.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;IE and FF also have their pseudo-elements: &lt;code&gt;:-moz-range-track&lt;/code&gt; and &lt;code&gt;::-moz-range-thumb&lt;/code&gt; for FF, &lt;code&gt;::-ms-track&lt;/code&gt; and &lt;code&gt;::-ms-thumb&lt;/code&gt; for IE&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Using this, we'll apply our custom styles, let's start with the tracker:&lt;/p&gt;

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

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"range"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nd"&gt;::-webkit-slider-runnable-track&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;1.2em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#29334f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&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 set a border around the tracker and hide all the overflow content, now should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fii6ilft72nh0uqojyjjq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fii6ilft72nh0uqojyjjq.png" alt="tracker box"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know, I know! It looks really ugly, so lets fix that by applying some style to the thumb:&lt;/p&gt;

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

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"range"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nd"&gt;::-webkit-slider-thumb&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;12px&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;45px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;-webkit-appearance&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="nl"&gt;border-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#29334f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-40px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-85px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-130px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="m"&gt;-175px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-220px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-265px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-310px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="m"&gt;-350px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-390px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-409px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&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;First remove the default look &amp;amp; feel for the thumb, then we create a box shadow (10 actually) for the thumb and position them one behind the other, so now the input looks better: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember, we have the shadowDOM active, if something doesn't look the same, just inspect the element and change the style as you need.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6bnfqjckrauh8mg2krcn.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6bnfqjckrauh8mg2krcn.gif" alt="Thumb styled"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, all we need to do is put some style in the &lt;code&gt;&amp;lt;datalist&amp;gt;&lt;/code&gt; element:&lt;/p&gt;

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

&lt;span class="nf"&gt;#custom-list&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#custom-list&lt;/span&gt; &lt;span class="nt"&gt;option&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&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;Our datalist have a display flex and its items are align with a space between them, next, we just position all the datalist element upfront our input range (it was at the top). Finally we just set left and right borders on each option element. This is how it looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjjenzzg219x56onxtrvz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjjenzzg219x56onxtrvz.png" alt="datalist styled"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even though our input range is start taking shape, still looks a little weird, so let's fix it.&lt;/p&gt;

&lt;p&gt;The first problem, is the first &lt;code&gt;option&lt;/code&gt; element with 2 borders, we don't need that, so let's hide it&lt;/p&gt;

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

&lt;span class="nf"&gt;#custom-list&lt;/span&gt; &lt;span class="nt"&gt;option&lt;/span&gt;&lt;span class="nd"&gt;:first-of-type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;visibility&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&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;But that's not enough, we also need to fix the height of &lt;code&gt;option&lt;/code&gt; so the top border of the &lt;code&gt;option&lt;/code&gt; element will overflow a little bit the top border of the tracker.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can base on the height we define for the &lt;em&gt;thumb&lt;/em&gt;, in this case: &lt;code&gt;12px&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;span class="nf"&gt;#custom-list&lt;/span&gt; &lt;span class="nt"&gt;option&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;...&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12.5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="err"&gt;just&lt;/span&gt; &lt;span class="err"&gt;a&lt;/span&gt; &lt;span class="err"&gt;little&lt;/span&gt; &lt;span class="err"&gt;bit&lt;/span&gt; &lt;span class="err"&gt;more&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;If we look at the end of our input range, we still se a weird border, something like "]" (is actually our input track), to fix that, let's set &lt;code&gt;overflow: hidden&lt;/code&gt; to the &lt;code&gt;.container&lt;/code&gt; element:&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;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;...&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&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;And last but not least, let's remove the ugly &lt;code&gt;focus&lt;/code&gt; effect that the input have by default:&lt;/p&gt;

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

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"range"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And there you go!! Now you have a great looking input range, using only a few lines of CSS.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Before&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frmh6hz5gtk0q5u6qqvz9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frmh6hz5gtk0q5u6qqvz9.gif" alt="Initial input range"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;After&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmk13h8zobzz7xfmacg0g.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmk13h8zobzz7xfmacg0g.gif" alt="Finished input range"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check the full code &lt;a href="https://codepen.io/christo-pr/pen/NWGgKNq" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding!! 💻🤓&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>frontend</category>
      <category>css</category>
    </item>
    <item>
      <title>RedwoodJS: Intro &amp; Web Side</title>
      <dc:creator>Cristofer</dc:creator>
      <pubDate>Tue, 14 Apr 2020 15:32:11 +0000</pubDate>
      <link>https://forem.com/christo_pr/redwoodjs-intro-web-side-3i8j</link>
      <guid>https://forem.com/christo_pr/redwoodjs-intro-web-side-3i8j</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgf2iwck4ptogchftwgqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgf2iwck4ptogchftwgqg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://redwoodjs.com" rel="noopener noreferrer"&gt;Redwoodjs&lt;/a&gt; is an &lt;strong&gt;opinionated serverless web framework&lt;/strong&gt; for Javascript, that allows you to create applications using the &lt;a href="https://jamstack.org" rel="noopener noreferrer"&gt;JAMstack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since it make you follow some code conventions (that will explore in this post) while coding, the developer experience is really lovely and I'm pretty sure after reading this post you will like to try it out!&lt;/p&gt;

&lt;h2&gt;
  
  
  First Impressions
&lt;/h2&gt;

&lt;p&gt;Topics like: &lt;strong&gt;ReactJS&lt;/strong&gt;, &lt;strong&gt;Apollo (GraphQL)&lt;/strong&gt;, &lt;strong&gt;Prisma&lt;/strong&gt;, &lt;strong&gt;Storybook&lt;/strong&gt;, &lt;strong&gt;Babel&lt;/strong&gt;, &lt;strong&gt;Webpack&lt;/strong&gt;, are really popular among web developers, and there's a good reason for that:&lt;br&gt;
They all make the developer experience great!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don't forget to mention that each tool resolves many other issues on it's own environment&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So now, imagine someone describe to you, their React frontend app, statically delivered by CDN, that talks via &lt;strong&gt;GraphQL&lt;/strong&gt; to their backend running on &lt;strong&gt;AWS Lambdas&lt;/strong&gt; around the world, all deployable with just a &lt;code&gt;git push&lt;/code&gt; command?&lt;/p&gt;

&lt;p&gt;Really cool uh?, Well this last paragraph it's exactly how &lt;a href="https://redwoodjs.com/docs" rel="noopener noreferrer"&gt;RedwoodJS is officially defined&lt;/a&gt;, so no more presentations needed, let's start digging into it!.&lt;/p&gt;
&lt;h2&gt;
  
  
  JAMstack
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;If you already understand what's the &lt;strong&gt;JAMstack&lt;/strong&gt; you can skip this section and just jump ahead to the &lt;strong&gt;Going through the web side&lt;/strong&gt; section.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;JAM&lt;/em&gt; stands for &lt;strong&gt;JavaScript, API &amp;amp; Markup&lt;/strong&gt;, and like you can imagine, it means that your app (if it applies) should be just about Markup (HTML) and Javascript (Using the API of the browers) and nothing else.&lt;br&gt;
It's just a way to think about the workflow of an app development, by removing a backend server.&lt;/p&gt;

&lt;p&gt;Nowadays the web need apps that are high-performant, have less security risk, and of course, there's a less cost when trying to scale them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do you achieve this?&lt;/strong&gt; By making it small and simple from the begging, which happens to be one features of the JAMstack.&lt;/p&gt;

&lt;p&gt;One of the many ways to define the JAMstack that I like more is the one from &lt;em&gt;Mathias Biilmann&lt;/em&gt;, CEO &amp;amp; Co-founder of Netlify:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"A modern web development architecture based on client-side JavaScript, reusable APIs, and prebuilt Markup"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It's &lt;a href="https://github.com/automata/awesome-jamstack" rel="noopener noreferrer"&gt;very likely that you already have interact with one of these apps&lt;/a&gt;, or even work in one if you have use any of the &lt;a href="https://www.staticgen.com" rel="noopener noreferrer"&gt;static site generators&lt;/a&gt; that are out there.&lt;/p&gt;

&lt;p&gt;For obvious reasons, the JAMstack doesn't fit for all the apps, so how we can know if our app applies to this stack? Easy, if your app &lt;strong&gt;doesn't relies on a tight coupling between client and server&lt;/strong&gt;, then you are on the right path.&lt;/p&gt;

&lt;p&gt;Also, if you are using a server-side CMS (Drupal, Wordpress, etc..) or building a monolithic app with Node, Ruby, etc... the JAMstack is not what you are looking for.&lt;/p&gt;

&lt;p&gt;So now you have a basic idea of what the JAMstack is, now let's check RedwoodJS.&lt;/p&gt;
&lt;h2&gt;
  
  
  Going through the web side
&lt;/h2&gt;

&lt;p&gt;RedwoodJS uses &lt;code&gt;node&lt;/code&gt; and &lt;code&gt;yarn&lt;/code&gt;, so you will need those to be installed on your computer. &lt;a href="https://redwoodjs.com/tutorial/prerequisites" rel="noopener noreferrer"&gt;Check Prerequisites Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create an app just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn create redwood-app ./my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's start talking about how RedwoodJS organize the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Organization
&lt;/h3&gt;

&lt;p&gt;By default, a RedwoodJS app has 2 &lt;strong&gt;sides&lt;/strong&gt;: &lt;code&gt;web&lt;/code&gt; and &lt;code&gt;api&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-app
|__api/
   |__prisma/
   |__migrations/
   |__src/
      |__functions/
      |__graphql/
      |__services/
   |__dev.db
|__web/
   |__public/
   |__src/
      |__components/
      |__layouts/
      |__pages/
   |__index.css
   |__index.html
   |__index.js
   |__Routes.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the &lt;code&gt;api&lt;/code&gt; folder, we have 3 more directories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;prisma/&lt;/code&gt;:  Contains the database schema and the seeds to pre-populate your database.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;migrations/&lt;/code&gt;: This folder will be created after running your first migration, and it contains snapshots of your database.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/&lt;/code&gt;: This directory contains another 3 directories inside: 

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;functions/&lt;/code&gt;: This is where all the labmda functions live, you will find some other files to configure your Graphql API.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;graphql/&lt;/code&gt;: Contains Schema Definition Language (SDL) files of your grapql schema&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;services/&lt;/code&gt;: Here you'll find all the business logic of your app, but in an abstract way, so it can be consume across all your app (&lt;strong&gt;web&lt;/strong&gt; &amp;amp; &lt;strong&gt;api&lt;/strong&gt;) in a consist way.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Now for the &lt;code&gt;web&lt;/code&gt; folder, we have a more simple structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;public/&lt;/code&gt;: This folder is for static resources&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/&lt;/code&gt;: This is where all the code for our React app will live:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;components/&lt;/code&gt;: Besides your regular React components, RedwoodJS stores the &lt;code&gt;Cells&lt;/code&gt; components in this directory too (we'll explore them later)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;layouts/&lt;/code&gt;: Not much to say here, just use it for all the layouts that your app could have&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pages/&lt;/code&gt;: This pages components, usually are wrapped by a layout component, and it's what the user see when they land on a url.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;RedwoodJS call these top-level folders (&lt;strong&gt;web&lt;/strong&gt; &amp;amp; &lt;strong&gt;api&lt;/strong&gt;) &lt;strong&gt;sides&lt;/strong&gt;, but underneath they are &lt;a href="https://classic.yarnpkg.com/en/docs/workspaces/" rel="noopener noreferrer"&gt;&lt;strong&gt;Yarn workspaces&lt;/strong&gt;&lt;/a&gt;, and of course there are a couple of features around using them.&lt;/p&gt;

&lt;h3&gt;
  
  
  The CLI
&lt;/h3&gt;

&lt;p&gt;RedwoodJS comes with a &lt;a href="https://redwoodjs.com/docs/the-redwood-command-line-interface" rel="noopener noreferrer"&gt;handy CLI app&lt;/a&gt; that let you run some task, like create an scaffold, create a database, running a migration, and so on.&lt;/p&gt;

&lt;p&gt;Here is the list of some of the commands I use more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yarn redwood dev&lt;/code&gt; or &lt;code&gt;yarn rw dev&lt;/code&gt;: Starts a development server&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn rw test&lt;/code&gt;: Run test suite using Jest&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn rw db save&lt;/code&gt;: Create a new migration&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn rw db up&lt;/code&gt;: Run any new migration and update the schema&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn rw db seed&lt;/code&gt;: Seed the database&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn rw generate &amp;lt;resource&amp;gt;&lt;/code&gt;: A generator for the given resource:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cell&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;component&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;layout&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;page&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;scaffold&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sdl&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;service&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;We'll look more into the resources later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alias Path
&lt;/h3&gt;

&lt;p&gt;Like I've mention, following some code conventions allows us to increase the developer experience and we can see an example with how RedwoodJS handle the routes.&lt;/p&gt;

&lt;p&gt;Let's create a new page using the cli:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn rw generate page hello /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the page generators accepts 2 parameters, one is the name of the page, and the other one is the url of that page.&lt;/p&gt;

&lt;p&gt;After running this command, you'll see a new directory inside &lt;code&gt;web/src/pages/&lt;/code&gt; called &lt;code&gt;HelloPage&lt;/code&gt;, as you can see RedwoodJS automatically takes the name you specified, capitalize it and append &lt;code&gt;Page&lt;/code&gt; to create the folder name.&lt;/p&gt;

&lt;p&gt;Let's see how our page component looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HelloPage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;HelloPage&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Find me in ./web/src/pages/HelloPage/HelloPage.js&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;HelloPage&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we no longer need to import React at the top of each component so we have more cleaner components.&lt;br&gt;
You'll also notice that all the react component are &lt;strong&gt;functional component&lt;/strong&gt;, and this is because they use &lt;strong&gt;React Hooks&lt;/strong&gt; a lot, you still can use class though, but they don't recommend it.&lt;/p&gt;

&lt;p&gt;Now let's take a look to the &lt;code&gt;Routes.js&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;}&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;@redwoodjs/router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;HelloPage&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;notfound&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;NotFoundPage&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, there's a new &lt;code&gt;Route&lt;/code&gt; component that points the &lt;code&gt;/&lt;/code&gt; url to the &lt;code&gt;HelloPage&lt;/code&gt; component. We can also notice a few other things happening on this file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Router&amp;gt;&lt;/code&gt; &amp;amp; &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; component are coming from redwoodjs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;HelloPage&lt;/code&gt; &amp;amp; &lt;code&gt;NotFoundPage&lt;/code&gt; components are not imported anywhere in this file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So how does it know where to find this component? Well, since pages are what the user see when they land on a url, its gonna be obvious that all the pages component would need to be imported here, so RedwoodJS automatically import it for you at build time, so you don't need to have a huge &lt;code&gt;Routes.js&lt;/code&gt; filled with &lt;code&gt;import ...&lt;/code&gt; statments.&lt;/p&gt;

&lt;p&gt;This feature also works with nested folders, but there's a rule: &lt;strong&gt;the have to be uppercase&lt;/strong&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/pages/HomePage/HomePage.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;         &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;HomePage&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/pages/Admin/BooksPage/BooksPage.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;AdminBooksPage&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Named routes
&lt;/h3&gt;

&lt;p&gt;Run this to create another page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn rw generate page about
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time we just specify the resource name without the route, when we do this, Redwood automatically uses that same name, to define the route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;AboutPage&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"about"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;HelloPage&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;notfound&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;NotFoundPage&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;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;RedwoodJS uses the &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component to handle the navigations between pages, let's take a look on how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="p"&gt;}&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;@redwoodjs/router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HelloPage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;HelloPage&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;about&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;See about&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;The &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; components accept a prop called &lt;code&gt;to&lt;/code&gt;, and as you can see we passed it a function from the &lt;code&gt;routes&lt;/code&gt; object. This is a &lt;strong&gt;named route function&lt;/strong&gt; calling this function will generate the correct url, and maybe you already figure it out, but the name of the property inside the &lt;code&gt;routes&lt;/code&gt; object is coming from the &lt;code&gt;name&lt;/code&gt; prop that we set on the &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;AboutPage&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"about"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, the &lt;code&gt;to&lt;/code&gt; prop also accepts a string, but a great thing about having this name route, is that we can change the url any time and all the links will be updated without having to do anything else.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cells
&lt;/h3&gt;

&lt;p&gt;Another good thing about Redwoodjs are &lt;code&gt;Cells&lt;/code&gt; components.&lt;/p&gt;

&lt;p&gt;When you work with React, is very common to step into the next scenario:&lt;/p&gt;

&lt;p&gt;You have to implement a simple listing page, that fetch data from your server, and then renders a list of items, easy!, but then you start asking yourself, what should I show when there's no items, or when there's been an error while fetching the data, or event what you show to the user while fetching this data!?&lt;/p&gt;

&lt;p&gt;All the sudden you have to implement a single listing component that handle up to 4 different states.&lt;/p&gt;

&lt;p&gt;The bad part is when you have this listing page for each resource of your app.&lt;/p&gt;

&lt;p&gt;Well RedwoodJS found this use case to be very repetitive and that's why they create a &lt;code&gt;Cell&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Cells&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;provide a simpler and more declarative approach to data fetching&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;That's how RedwoodJS define a &lt;code&gt;Cell&lt;/code&gt; component. Okay, let's see them in action.&lt;/p&gt;

&lt;p&gt;The next example would probably looks weird since we have not talk about the &lt;strong&gt;api side&lt;/strong&gt;, but for now, you can just think that there's a grahpql model called &lt;code&gt;post&lt;/code&gt; and all the backend works outta of magic.&lt;br&gt;
&lt;em&gt;We'll talk about the api side on the next post&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;QUERY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  query {
    posts {
      id
      title
      body
      createdAt
    }
  }
`&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Loading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Loading...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Empty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;No posts yet!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Failure&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Error loading posts: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;article&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;article&lt;/span&gt;&lt;span class="p"&gt;&amp;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;Ok, I know there's a lot going on here, so lets just untangle all:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There's a variable called &lt;code&gt;QUERY&lt;/code&gt; been exported from this file and it holds a &lt;a href="https://github.com/graphql/graphql-js" rel="noopener noreferrer"&gt;gql&lt;/a&gt; query&lt;/li&gt;
&lt;li&gt;There are 4 components been exported also: &lt;code&gt;Loading&lt;/code&gt;, &lt;code&gt;Empty&lt;/code&gt;, &lt;code&gt;Failure&lt;/code&gt; and &lt;code&gt;Success&lt;/code&gt;, each of one render a different UI representing the state of the component.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So what happens here, once React has made the render, RedwoodJS will execute the grahpql query from the &lt;code&gt;QUERY&lt;/code&gt; variable while it renders the &lt;code&gt;Loading&lt;/code&gt; component, once the call is done, it will render either &lt;code&gt;Empty&lt;/code&gt;, &lt;code&gt;Failure&lt;/code&gt; or &lt;code&gt;Success&lt;/code&gt; component based on the query response.&lt;/p&gt;

&lt;p&gt;Additionally you could use the &lt;code&gt;beforeQuery&lt;/code&gt; and &lt;code&gt;afterQuery&lt;/code&gt; lifecyles to do modify the props before they go to the &lt;code&gt;Success&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;You can omit the &lt;code&gt;Empty&lt;/code&gt; and &lt;code&gt;Failure&lt;/code&gt; components, and after an empty data response, the &lt;code&gt;Success&lt;/code&gt; component will be rendered or if there's any error will be outputted to the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up: Web Side
&lt;/h2&gt;

&lt;p&gt;Even though there a lot of libraries and frameworks out there, TBH RedwoodJS looks really unique to me when it comes to a fast development, great developer experience and huge performance for develop web apps using the JAMstack.&lt;/p&gt;

&lt;p&gt;The sad part? RedwoodJS is still in &lt;strong&gt;alpha&lt;/strong&gt; version, so it's not production-ready yet, but they have an &lt;a href="https://redwoodjs.com/tutorial/wrapping-up" rel="noopener noreferrer"&gt;interesting roadmap&lt;/a&gt;, so feel free to try it out or even better &lt;a href="https://github.com/redwoodjs/redwood/issues" rel="noopener noreferrer"&gt;contribute to the framework&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the next post we'll look into the API side of the framework and check what RedwoodJS offer us!&lt;/p&gt;

&lt;p&gt;Thanks for reading! 👋🏻👋🏻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>react</category>
    </item>
    <item>
      <title>Beacon API</title>
      <dc:creator>Cristofer</dc:creator>
      <pubDate>Thu, 13 Feb 2020 18:59:41 +0000</pubDate>
      <link>https://forem.com/christo_pr/beacon-api-1g7p</link>
      <guid>https://forem.com/christo_pr/beacon-api-1g7p</guid>
      <description>&lt;p&gt;Modern browsers are increasingly venturing into the native interaction with the hardware, they offer us an small, but helpful &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API"&gt;list of APIs&lt;/a&gt; to have fun.&lt;/p&gt;

&lt;p&gt;Some of them have a more native interactions, and some of them are more like utilities that can help developers.&lt;/p&gt;

&lt;p&gt;This is the case for the &lt;strong&gt;Beacon API&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;It's very likely you'll find yourself, at some point of your web developer career, working with &lt;strong&gt;analytics.&lt;/strong&gt; This type of scripts often need to do something (eg. reporting) when the &lt;code&gt;document&lt;/code&gt; triggers an &lt;code&gt;unload&lt;/code&gt; event, normally would be a call to a server maybe to let know that a user just left the page just before checkout (ouch!)&lt;/p&gt;

&lt;p&gt;The first piece of code that comes to my mind when I encounter this scenario looks 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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onunload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;userLeave&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Do the http request to my analytics server&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, turns out that browsers, ignore asynchronous http calls that happen during an &lt;code&gt;unload&lt;/code&gt; event.&lt;/p&gt;

&lt;p&gt;Again, first solution that comes to my mind: &lt;strong&gt;let's make it synchronous&lt;/strong&gt;. Well, although it works, doing a synchronous action inside the &lt;code&gt;unload&lt;/code&gt; event will force the browsers to &lt;strong&gt;wait&lt;/strong&gt; until this event has completely finish, therefore the next page will feel slow to load.&lt;/p&gt;

&lt;p&gt;There are other techniques to handle this scenario, but they all involves a &lt;strong&gt;bad code practice&lt;/strong&gt; and affect the user navigation&lt;/p&gt;

&lt;h2&gt;
  
  
  Send a Beacon! 🗼🗼
&lt;/h2&gt;

&lt;p&gt;To solve this issue, the browsers offers us the &lt;code&gt;Beacon API&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;navigator&lt;/code&gt; object has a method called &lt;code&gt;sendBeacon()&lt;/code&gt;, this method receives 2 parameters: &lt;code&gt;url&lt;/code&gt; and &lt;code&gt;options&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;url&lt;/code&gt; parameter represents the url of the server you want to send the request, and the &lt;code&gt;options&lt;/code&gt; parameter (&lt;strong&gt;optional&lt;/strong&gt;) can be a simple &lt;strong&gt;String&lt;/strong&gt;, or if you want to send more complex data, you could also pass an &lt;code&gt;ArrayBufferView&lt;/code&gt;, &lt;code&gt;Blob&lt;/code&gt;, &lt;code&gt;DOMString&lt;/code&gt;, or &lt;code&gt;FormData&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This function schedules an http &lt;strong&gt;POST&lt;/strong&gt; request using the parameters you passed in (url and options), it returns &lt;code&gt;true&lt;/code&gt; if the http call was successfully scheduled, returns &lt;code&gt;false&lt;/code&gt; otherwise&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onunload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;userLeave&lt;/span&gt;&lt;span class="p"&gt;()&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;crashData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;FormData&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://my-analytics-server/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

  &lt;span class="nx"&gt;crashData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;userID&lt;/span&gt;&lt;span class="dl"&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;123&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sendBeacon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;crashData&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;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Beacon requests use  only HTTP POST and do not require a response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Beacon requests are guaranteed to be initiated before the page unloads.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;You should check out all the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API/Using_the_Beacon_API"&gt;examples&lt;/a&gt; from the docs to see how this can help you in many other cases!&lt;/p&gt;

&lt;p&gt;Thanks for reading 🤚&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Render dangerous content with React</title>
      <dc:creator>Cristofer</dc:creator>
      <pubDate>Mon, 03 Feb 2020 21:30:55 +0000</pubDate>
      <link>https://forem.com/christo_pr/render-dangerous-content-with-react-2j7j</link>
      <guid>https://forem.com/christo_pr/render-dangerous-content-with-react-2j7j</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;FYI All the content of this post suits best for some edge cases, and the solution proposed here is probably not the more safe way to do it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Cross-site Scripting (XSS Attacks)
&lt;/h2&gt;

&lt;p&gt;Among all the web vulnerabilities, one of the most common is &lt;a href="https://owasp.org/www-community/attacks/xss/" rel="noopener noreferrer"&gt;cross-site scripting&lt;/a&gt;, this type of vulnerability allows the attackers to &lt;strong&gt;inject&lt;/strong&gt; scripts on the page to get access to any sensitive information the browser and the site are sharing (cookies, tokens, etc...).&lt;/p&gt;

&lt;p&gt;This attack occurs when the data entered is coming from an untrusted source or the data that is sent to the user include dynamic content without been validated first.&lt;br&gt;
Although there are limitless varieties of XSS attacks, Javascript XSS attacks seems to be popular among hackers.&lt;/p&gt;
&lt;h3&gt;
  
  
  Types of XSS Attacks
&lt;/h3&gt;

&lt;p&gt;There are 3 types of XSS attacks:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stored XSS Attacks&lt;/strong&gt; occurs when the injected script is store on the server (i.e. store on a database) so each time the user request a something from the server&lt;br&gt;
the malicious script is sent to the client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reflected XSS Attacks&lt;/strong&gt; happens when the malicious script is reflect on the web that's vulnerable, this could be due to a click on an email link that's malformed or any other external source.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DOM Based XSS Attacks&lt;/strong&gt; is a vulnerability that occurs on the DOM (Document Object Model) instead of the HTML.&lt;/p&gt;

&lt;p&gt;Let's say you have this code on your app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
   &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;h1&amp;gt;My URL:&amp;lt;/h1&amp;gt;: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseURI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, imagine someone visits your site using the URL &lt;code&gt;https://www.nicesite.com/index.html#&amp;lt;script&amp;gt;alert('test')&amp;lt;/script&amp;gt;&lt;/code&gt;, the script will be executed because the code above writes whatever comes on url to the document using &lt;code&gt;document.write&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can point one of the main differences between this type of XSS attack and the Stored and Reflected: The servers &lt;strong&gt;can't stop&lt;/strong&gt; this attack, since the &lt;em&gt;hash&lt;/em&gt; (#) part of the url is not being sent to the server on the request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prevent XSS Attacks
&lt;/h3&gt;

&lt;p&gt;For most of the XSS attacks the solution is simple, just &lt;a href="https://medium.com/@abderrahman.hamila/what-sanitize-mean-and-why-sanitize-in-code-data-5c68c9f76164" rel="noopener noreferrer"&gt;sanitize&lt;/a&gt; your input data, even if comes from a &lt;strong&gt;&lt;em&gt;trusted&lt;/em&gt;&lt;/strong&gt; source.&lt;br&gt;
Doing this will ensure that no matter what's the input or output, is always secure.&lt;/p&gt;

&lt;p&gt;Javascript offers us plenty ways to interact with the DOM, so we can works with dynamic content in an easy way, but we need to be careful on how to use it, since it can make vulnerable our websites.&lt;/p&gt;
&lt;h4&gt;
  
  
  Inputs &amp;amp; Outputs
&lt;/h4&gt;

&lt;p&gt;Here's a tiny list of the most common input and outputs that can be dangerous to use.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Inputs&lt;/th&gt;
&lt;th&gt;Outputs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;document.URL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;document.write&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;document.documentURI&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;element.innerHTML&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;location.href&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;element.src&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  React and cross-site scripting
&lt;/h2&gt;

&lt;p&gt;Nowadays all the web apps required some dynamism, from having a multiple step form that shows different question depending on your answers to a simple tables that filter out information, this is where Javascript enters to the equation.&lt;/p&gt;

&lt;p&gt;Back in time, when Javascript vainilla was enough to get everything done (which still is, we just &lt;em&gt;'syntax-sugar'&lt;/em&gt; it), one of the way you could handle insertion of dynamic content, was using &lt;code&gt;innerHTML&lt;/code&gt; property.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Element.innerHTML:&lt;/p&gt;

&lt;p&gt;The Element property &lt;strong&gt;innerHTML&lt;/strong&gt; gets or sets the HTML or XML markup contained within the element&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, you can set the HTML content from an element using this property, but what happen when the content has an &lt;code&gt;script&lt;/code&gt; inside?&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;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Christofer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;el&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="nx"&gt;content&lt;/span&gt;


&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;script&amp;gt;alert('You've been hacked')&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;el&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="nx"&gt;newContent&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first 2 lines create a variable that holds a plain string, then using &lt;code&gt;innerHTML&lt;/code&gt; set the content of an element to be this value, so far so good, nothing harmless here.&lt;/p&gt;

&lt;p&gt;On the next 2 lines of code we do the same, but this time, the string value is html-like with a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag within it, so what would you think will be the output?&lt;/p&gt;

&lt;p&gt;Well, if you though that this will result on an alert prompting to the user that he has been hacked, well you are &lt;strong&gt;wrong&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;HTML5 specifications says that scripts inserted using &lt;code&gt;innerHTML&lt;/code&gt; &lt;a href="https://www.w3.org/TR/2008/WD-html5-20080610/dom.html#innerhtml0" rel="noopener noreferrer"&gt;shouldn't execute.&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Easy to be safe
&lt;/h4&gt;

&lt;p&gt;React follows the philosophy &lt;em&gt;"easy to be safe"&lt;/em&gt;, that's why we as developers should be explicit if we want to go for the &lt;em&gt;unsafe&lt;/em&gt; path, and this is the case for the &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; prop.&lt;/p&gt;

&lt;p&gt;This prop allows you to inject dynamic html to an element, all you need to do is pass and object with a single property: &lt;code&gt;__html&lt;/code&gt;, with a string html-like of what you want to render:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&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;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt; Injected html&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&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="nx"&gt;dangerouslyInnerHTML&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;__html&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;As you can see, seems a little odd that you have to pass an object when it could be a simple string, but this is done intentionally, to remind you that it's dangerous and you should avoid using it as much as possible.&lt;/p&gt;

&lt;h4&gt;
  
  
  innerHTML vs dangerouslySetInnerHTML
&lt;/h4&gt;

&lt;p&gt;Writing React doesn't mean that you can't use the features that Javascript offer us, you can use &lt;code&gt;innerHTML&lt;/code&gt; to add the dynamic html to a react component and it will work the same (both will update the node with the html), but it can lead to undesired performance issues.&lt;/p&gt;

&lt;p&gt;React uses a &lt;strong&gt;virtual DOM&lt;/strong&gt; and a &lt;strong&gt;diffing algorithm&lt;/strong&gt; to compare what's been updated and re-render the content, this process is called &lt;a href="https://reactjs.org/docs/reconciliation.html" rel="noopener noreferrer"&gt;&lt;strong&gt;reconciliation&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; you can tell React to ignore all the dynamic html during reconciliation&lt;/p&gt;

&lt;p&gt;When you use &lt;code&gt;innerHTML&lt;/code&gt; to set the content, all the dynamic html that was generated is included in the reconciliation process, aside performance issues, React could wrongly update the dynamic html.&lt;/p&gt;

&lt;p&gt;Since both properties works the same (in fact &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; implements &lt;code&gt;innerHTML&lt;/code&gt; to set the content) they both share kinda the same vulnerabilities, hence the importance of sanitizing your input sources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Render the danger
&lt;/h2&gt;

&lt;p&gt;Now what happens when you want to use &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; but also need to execute any &lt;code&gt;script&lt;/code&gt; tag that comes inside the html? That's against HTML5 specifications, but if we dig a little bit more on what &lt;code&gt;innerHTML&lt;/code&gt; do to inject the html we can found something interesting:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The specified value is parsed as HTML or XML (based on the document type), resulting in a &lt;strong&gt;DocumentFragment&lt;/strong&gt; object representing the new set of DOM nodes for the new elements.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This &lt;strong&gt;DocumentFragment&lt;/strong&gt; is a lightweight version of the &lt;code&gt;document&lt;/code&gt;, it can have child nodes, the main difference is that since is a fragment, is not actually a part of the active/main &lt;code&gt;document&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can create a &lt;strong&gt;DocumentFragment&lt;/strong&gt; using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Range" rel="noopener noreferrer"&gt;document.Range&lt;/a&gt; API.&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;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
  &amp;lt;h1&amp;gt;Fragment&amp;lt;/h1&amp;gt;
`&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRange&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;createContextualFragment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet will create a &lt;code&gt;DocumentFragment&lt;/code&gt; object, parse the value of the &lt;code&gt;html&lt;/code&gt; variable and store the result on a variable called &lt;code&gt;node&lt;/code&gt;. All we have to do is render this variable:&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;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appenChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we translate all of this to a React component we end up with 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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt; &lt;span class="p"&gt;}&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// InnerHTML component&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;InnerHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;divRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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;parsedHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRange&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;createContextualFragment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;divRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parsedHTML&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="k"&gt;return &lt;/span&gt;&lt;span class="p"&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="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;divRef&lt;/span&gt;&lt;span class="p"&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="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&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;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;h1&amp;gt;Fragment&amp;lt;/h1&amp;gt;
  `&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;InnerHTML&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;This way we could pass a string with html content that includes &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags, and those will be executed (works with &lt;code&gt;&amp;lt;script&amp;gt; .. content .. &amp;lt;/script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;script src="file.js" /&amp;gt;&lt;/code&gt;)&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzewdof8sob5gc74nxy0u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzewdof8sob5gc74nxy0u.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/dangerously-set-html-content" rel="noopener noreferrer"&gt;dangerously-set-html-content&lt;/a&gt; is a tiny (&lt;strong&gt;297B Gzipped&lt;/strong&gt;), &lt;strong&gt;no-dependencies&lt;/strong&gt;, library that allows you to render dynamic html and execute any &lt;code&gt;scripts&lt;/code&gt; tag within it.&lt;/p&gt;

&lt;p&gt;1) Add it to your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add dangerously-set-html-content
// or
// npm &lt;span class="nb"&gt;install &lt;/span&gt;dangerously-set-html-content &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Start using it:&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;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;InnerHTML&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;dangerously-set-html-content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&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;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Fragment&amp;lt;/h1&amp;gt;
      &amp;lt;script&amp;gt;
        alert('this will be executed');
      &amp;lt;/script&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;InnerHTML&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Of course this doesn't prevent any attack (in fact, does the opposite of that), but sometimes this functionally could be what you are looking for.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I built this because I actually needed this functionality.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;All the web is full of vulnerabilities that can cause you headaches if you are not aware of how to prevent them. Mostly of the common frontend libraries already handle a few of these in a way, so you don't have to worry about it‌ but still is good to know what we are dealing with as front-end developers.&lt;/p&gt;

&lt;p&gt;Additionally of what React offers us, there are several techniques that can help you to prevent an attack, so if you are having a problem of this type just head to the docs and you'll probably find the solution.&lt;/p&gt;

&lt;p&gt;While 99% of the time all this &lt;em&gt;magic&lt;/em&gt; behind React works perfectly for us, sometimes we can found ourselves struggling with it, but at the end is just Javascript so embracing both will help us to find the solution to our problem.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How do I write React</title>
      <dc:creator>Cristofer</dc:creator>
      <pubDate>Mon, 03 Feb 2020 19:15:04 +0000</pubDate>
      <link>https://forem.com/christo_pr/how-do-i-write-react-4pan</link>
      <guid>https://forem.com/christo_pr/how-do-i-write-react-4pan</guid>
      <description>&lt;p&gt;I've write a lot of Javascript through my short career, and one the many things that I have learned is that, &lt;strong&gt;bad code still works on Javascript.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What I like about Javascript is how flexible it is, you can split your code into different files, put them anywhere you want, pass the path to the require() function and you are good to go, you don't need a strict folder structure for the app to be working.&lt;/p&gt;

&lt;p&gt;This is good when you are been introduced to programming, but this is also one of the reason why people don't get along with Javascript.&lt;/p&gt;

&lt;p&gt;React doesn't help with this problem, in fact it could complicate things even more, that's why I've decided to follow some rules when writing React.&lt;/p&gt;

&lt;p&gt;I describe them in this blog post, some of them might seem odd to you, some of them not, take what works for you and pass it to the next!&lt;/p&gt;

&lt;h1&gt;
  
  
  Javascript linter
&lt;/h1&gt;

&lt;p&gt;Even though this post is about React, we can't write clean React code, without writing clean Javascript code first.&lt;/p&gt;

&lt;p&gt;Every time I write Javascript I like to use a linter to check some basic code style rules.&lt;/p&gt;

&lt;p&gt;I used to use &lt;a href="https://eslint.org"&gt;ESLint&lt;/a&gt;, which is pretty common among JS developers, but then I found &lt;a href="https://standardjs.com"&gt;StandardJS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;StandardJS has some special rules (it doesn't use semi-colon, you can't ignore a rule), that make it look like really strict but it's precisely this set of standard rules what makes it great.&lt;/p&gt;

&lt;p&gt;It's really easy to use, all you have to do is add it to your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add standard
// or
// npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; standard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;You don't need a configuration file to start using the linter.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's a lot of discussions about programming style in js (tabs vs spaces, semi-colons) that's why I like standard, because it picks some 'standard' rules and that's all you have, no more, no less therefore no more discussions.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Automatically fix your problems (just use the &lt;code&gt;--fix&lt;/code&gt; flag).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I always create 2 npm scripts: &lt;code&gt;npm run lint&lt;/code&gt; and &lt;code&gt;npm run lint:fix&lt;/code&gt;.&lt;br&gt;
The first script is what I use more often, that shows all the errors with information about the line and file where they occurs.&lt;br&gt;
The second script is just to automatically fix the common errors, but I still try to manually fix as much as possible.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Git pre-commit hook.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes when I'm more strict about the programming style, I create a &lt;a href="https://standardjs.com/#is-there-a-git-pre-commit-hook"&gt;pre-commit&lt;/a&gt; hook for the project, that can save some review time.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Initializing a react project
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;npm registry&lt;/code&gt; is one of the biggest databases of public and private libraries for javascript. It offers a command line client to use all the features like, download, upload and do some other things, that allow you to interact with several javascript packages.&lt;/p&gt;

&lt;p&gt;There's one particular package that I use a lot when creating a react app: &lt;a href="https://github.com/zkat/npx#readme"&gt;npx&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This lib allows you to &lt;strong&gt;execute&lt;/strong&gt; the package binaries files, it executes the &lt;code&gt;&amp;lt;command&amp;gt;&lt;/code&gt; you passed in, following an specific order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local &lt;code&gt;node_modules/.bin&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;A central cache&lt;/li&gt;
&lt;li&gt;Install it and execute&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Why &lt;code&gt;npx&lt;/code&gt; instead of &lt;code&gt;npm&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;Honestly, I just don't like to struggle with all the versions and deprecations stuff, with &lt;code&gt;npx&lt;/code&gt; I ensure that the library that I'm using is on the latest stable version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx &amp;lt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use &lt;code&gt;npm&lt;/code&gt; to download React and start your project from scratch (configure Webpack to do all the fancy stuff you are used to have 'out-of-the-box') or you can use &lt;a href="https://github.com/facebook/create-react-app"&gt;create-react-app&lt;/a&gt; (CRA).&lt;/p&gt;

&lt;p&gt;This library allow you to bootstrap a React project. It has all the configurations needed for a rapid development with React (like hot reload, ES6 support, etc...)&lt;/p&gt;

&lt;p&gt;One of the good things about CRA, is the ability to have all the latest patches and features with a single bump version of your &lt;code&gt;react-scripts&lt;/code&gt; dependency (which is what CRA uses), so you don't have to worry for this anymore. CRA also allows you to have your custom setup by &lt;strong&gt;ejecting&lt;/strong&gt; your application, this action will give you the full control of the Webpack configuration, so you can twist it and do whatever you want with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  npx &amp;amp; create-react-app
&lt;/h2&gt;

&lt;p&gt;So now you know all the benefits of using &lt;code&gt;npx&lt;/code&gt; and &lt;code&gt;create-react-app&lt;/code&gt;, you can start figuring out how we can mix up these 2 libraries to simplify the creation of a React application.&lt;/p&gt;

&lt;p&gt;Each time I start a new React project I just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app awesomeApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That command will download (the latest-stable version) CRA and executes it, that's why we need to pass the name of the project we want to use (&lt;em&gt;awesomeApp&lt;/em&gt;).&lt;/p&gt;

&lt;h1&gt;
  
  
  Organize app structure
&lt;/h1&gt;

&lt;p&gt;CRA offers a very basic folder structure for your app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; awesomeApp/
  |__public/
  |__src/
    |__App.css
    |__App.js
    |__App.test.js
    |__index.css
    |__index.js
    |__logo.svg
    |__serviceWorker.js
    |__setupTests.js
  |__.gitignore
  |__package.json
  |__README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Some apps that I have in production are so simple that this folder structure is enough to work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I know that a project will be a little more complicated than that, I change the folder structure so that it's easy for me or any other developer make changes.&lt;/p&gt;

&lt;p&gt;I split my components in two types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Components&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Containers&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following this idea, the folder structure that I use, looks like pretty much like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; awesomeApp/
  |__public/
  |__src/
    |__components/
      |__ui/
    |__containers/
    |__utils/
    |__App.css
    |__App.js
    |__App.test.js
    |__index.css
    |__index.js
    |__logo.svg
    |__serviceWorker.js
    |__setupTests.js
  |__.gitignore
  |__package.json
  |__README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Components
&lt;/h5&gt;

&lt;p&gt;This is where I put all my UI components, that means, components that doesn't do to much of a logic, they are just there to present some information to the user and depend a little bit from the props that we passed in.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ui/&lt;/code&gt; folder holds all the components that are related to the User Interface (i.e. custom component for commons elements like &lt;code&gt;&amp;lt;CustomInput /&amp;gt;&lt;/code&gt; instead of &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;CustomImg /&amp;gt;&lt;/code&gt; instead of &lt;code&gt;&amp;lt;img /&amp;gt;&lt;/code&gt;)&lt;/p&gt;

&lt;h5&gt;
  
  
  Containers
&lt;/h5&gt;

&lt;p&gt;This is where I put the &lt;em&gt;smart&lt;/em&gt; components. A smart component is the one that controls the state of a particular part of the app. I use this type of components to wrap the most of the base markdown of the pages.&lt;/p&gt;

&lt;p&gt;Also I create a new folder called &lt;code&gt;utils/&lt;/code&gt;, which I use for all the utility functions that I'd use across the app.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; When I work with React Native, I just rename the &lt;code&gt;containers/&lt;/code&gt; folder to &lt;code&gt;pages/&lt;/code&gt;, seems better name for me.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Organize Code
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;index.js&lt;/code&gt; file contains all the code that register the service working and also render your app. So this file is basically your entry point, I suggest not to touch this file unless you really have to.&lt;/p&gt;

&lt;p&gt;Then we have the &lt;code&gt;App.js&lt;/code&gt; file, which is the React component that's been rendered on the &lt;code&gt;index.js&lt;/code&gt; file. I use this file as my main React file, and I try to keep it as simple as possible.&lt;/p&gt;

&lt;p&gt;Most of my &lt;code&gt;App.js&lt;/code&gt; file look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MainContainer&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;./containers/MainContainer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MainContainer&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can point up some things here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1) It's a functional component instead of a class component.&lt;/li&gt;
&lt;li&gt;2) It does nothing but render a main container component&lt;/li&gt;
&lt;li&gt;3) Export a default function which is the actual component&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  1) It's a functional component instead of a class component:
&lt;/h5&gt;

&lt;p&gt;I used to use class components all the time, so that I could have an state and control everything with the lifecycles of React but since hooks came out, all my components started to shrink a lot, and I liked that, so I haven't needed a class component anymore.&lt;/p&gt;

&lt;h5&gt;
  
  
  2) It does nothing but render a main container component:
&lt;/h5&gt;

&lt;p&gt;I always try to keep this component clean, unless I need some initial data that's coming from outside (i.e. API calls). So this will only return the main container, which will have all the business logic.&lt;/p&gt;

&lt;p&gt;I often use this function to wrap my app with a High Order Component (HOC), like react router or any css theme, so that's available for any children component.&lt;/p&gt;

&lt;h5&gt;
  
  
  3) Export a default function which is the actual component
&lt;/h5&gt;

&lt;p&gt;Each time I jump to an existing project and try to figure out all the imports a single file is doing, is really annoying to be searching if there's any export in a particular line, or if they default export a function that's been declare in line 128, that's why I prefer to have all my exports at the end of the file, so each time I wanted to see what's been exported, I just go the end of the file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Props and State
&lt;/h3&gt;

&lt;p&gt;I used to use class components for my &lt;strong&gt;containers/pages&lt;/strong&gt; and functional components for all other component, this way I could separate the concerns for each type of component.&lt;/p&gt;

&lt;p&gt;Now since hooks are live, I found myself writing cleaner components using functional components and hooks.&lt;/p&gt;

&lt;h5&gt;
  
  
  Class components
&lt;/h5&gt;

&lt;p&gt;A simple class component of my own looks 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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;HomeContainer&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&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;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nx"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Initialization of component's state&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;customMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 'this' is safe&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prop2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;

    &lt;span class="c1"&gt;// Render anything&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;HomeContainer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, I import React, some people use destructuring to import &lt;code&gt;Component&lt;/code&gt; also, I use the React variable since &lt;code&gt;Component&lt;/code&gt; is available as a property of the default export of react.&lt;/p&gt;

&lt;p&gt;I also &lt;a href="https://hackernoon.com/the-constructor-is-dead-long-live-the-constructor-c10871bea599"&gt;don't use constructor&lt;/a&gt;, I prefer to use &lt;a href="https://github.com/tc39/proposal-class-fields"&gt;class properties&lt;/a&gt; to define the state, and use the lifecycles of react to fetch initial data or to update state on renders.&lt;/p&gt;

&lt;p&gt;I've always though that the use of &lt;code&gt;this&lt;/code&gt; in javascript is really hardcore, but I liked though, seems to me like if you had all the javascript wisdom just because &lt;code&gt;.bind&lt;/code&gt; is in your code.&lt;br&gt;
I change all of that when working with React, (even tough I still think that using &lt;code&gt;this&lt;/code&gt; is cool if that solves your problem) instead of the regular method declaration of the classes I use an arrow function assignment, so &lt;code&gt;this&lt;/code&gt; keyword works as expected and looks cleaner.&lt;/p&gt;

&lt;p&gt;The first line of the &lt;code&gt;render()&lt;/code&gt; method is always the desctructuring of all the props of the component, so next time I come across this component, I know easily which props I'm using without having to dig into all the jsx code (which supposed to be clean).&lt;/p&gt;

&lt;p&gt;And last but not least, I export the component at the end of the file.&lt;/p&gt;
&lt;h5&gt;
  
  
  Functional components
&lt;/h5&gt;

&lt;p&gt;For functional components I follow kinda the same rules:&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;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;HomeContainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prop2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;

  &lt;span class="c1"&gt;// '[]' == no deps == one execution == componentDidMount&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Initialization of component's 'state'&lt;/span&gt;

  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt; 

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;// All the render&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;HomeContainer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So I still use the same destructuring-first technique for the props.&lt;/p&gt;

&lt;p&gt;When I need to do some state initialization of my functional components (i.e using &lt;code&gt;useState&lt;/code&gt; hook) I use the &lt;code&gt;useEffect&lt;/code&gt; hook, which is the replacement for the lifecycles on the class components.&lt;/p&gt;

&lt;p&gt;Finally I export my component at the end of file.&lt;/p&gt;

&lt;h5&gt;
  
  
  Handle JSX
&lt;/h5&gt;

&lt;p&gt;JSX is the syntax extension for javascript, it looks like html tags, and allows you to manipulate the UI of your components.&lt;/p&gt;

&lt;p&gt;There are some rules when using JSX though, one of the most known rule is the use of &lt;code&gt;className&lt;/code&gt; instead of &lt;code&gt;class&lt;/code&gt; for the html tag property, this is because the special keyword &lt;code&gt;class&lt;/code&gt; in Javascript represents a class declaration and it's reserved.&lt;/p&gt;

&lt;p&gt;Another special rule for jsx is that it doesn't allow multiple elements to be rendered, 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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;CheckBox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;Checkbox&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/label&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="nx"&gt;input&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;checkbox&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;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;This component is not jsx-valid, since you can't render multiple elements from a React component, instead you have to wrap all the content within a parent element. Most people use a &lt;code&gt;div&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;CheckBox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&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="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Checkbox&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/label&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="nx"&gt;input&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;checkbox&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&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="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;This works perfectly mostly of the time, but there are some special cases where this could be an issue (i.e. inside of a table row, you can't have a &lt;code&gt;div&lt;/code&gt; element as a child), so for those cases, the React team&lt;br&gt;
build &lt;code&gt;Fragment&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;Fragment&lt;/code&gt; you can safely return multiple elements without worrying about the semantic of the html&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;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;CheckBox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Fragment&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Checkbox&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/label&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="nx"&gt;input&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;checkbox&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&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="sr"&gt;/React.Fragment&amp;gt; /&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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's a shortcut for &lt;code&gt;Fragment&lt;/code&gt; that you can use instead: &lt;code&gt;&amp;lt;&amp;gt; ... &amp;lt;/&amp;gt;&lt;/code&gt; but you have to choose when to use it, since this shortcut &lt;strong&gt;doesn't accept any prop&lt;/strong&gt; while the &lt;code&gt;Fragment&lt;/code&gt; component let you use the &lt;code&gt;key&lt;/code&gt; prop, which is helpful when creating elements within a loop.&lt;/p&gt;

&lt;h1&gt;
  
  
  Organize your dependencies
&lt;/h1&gt;

&lt;p&gt;When I started working with javascript, I loved how the community helps to solve any kind of issue. Almost anything you would need when creating an app is likely to have it's own library/sdk than can help you with that.&lt;br&gt;
At first glance, that's good, but it can lead you to a &lt;strong&gt;&lt;em&gt;laziness&lt;/em&gt;&lt;/strong&gt; development, where you are used to find a library for nearly any feature you'd need, so when you don't find the library, you start thinking that it might be hard to do (at least that was what I though :sad:).&lt;/p&gt;

&lt;p&gt;In order to remove that bad habit of &lt;strong&gt;depend&lt;/strong&gt; a lot of my &lt;strong&gt;dependencies&lt;/strong&gt; (that's what the name stands for ??), I started to take a look to the code that I included on my projects, and that's how I realize that some of it it's really simple that it might wont worth to be included, and can be just a new file in the &lt;code&gt;utils/&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;I also try to think twice before install a dependency that's kinda small (I used to include &lt;a href="https://momentjs.com"&gt;momentjs&lt;/a&gt; on each project that I needed to present a simple formatted date) so my &lt;code&gt;node_modules/&lt;/code&gt; folder doesn't grow up too much.&lt;/p&gt;
&lt;h5&gt;
  
  
  Versioning on your dependencies
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;Versionin&lt;/strong&gt; is a huge problem on the Javascript environment (I supposed that all languages have this problem). You install the version 9.x of a dependency, and it works perfectly on your React 16.3, but then after a few months (or even weeks) in production, a new version of that library came out, and you just deploy normally to production, then &lt;code&gt;npm install&lt;/code&gt; do it's job. Next, you have a white screen (no matter how many times you reload the page) presented to your users, ugh!!&lt;/p&gt;

&lt;p&gt;With npm, you can use &lt;a href="https://github.com/npm/node-semver#ranges"&gt;Range versions&lt;/a&gt; to control the version of your dependencies, by default it's configure to use the &lt;strong&gt;caret range&lt;/strong&gt;, that means patch and minor updates are allowed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;^1.0.0 =&amp;gt; 1.x.x
~1.0.0 =&amp;gt; 1.x.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So when you install a package, your package json looks pretty much 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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dependencies&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;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^16.3.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;momentjs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^4.3.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though that &lt;code&gt;minor&lt;/code&gt; and &lt;code&gt;patch&lt;/code&gt; updates should not break your code, not everyone follow that rule, and sometimes you can struggle with that for a long time without notice that it's because of the library version.&lt;br&gt;
That's why I &lt;strong&gt;lock&lt;/strong&gt; the version of my dependencies (I just remove the caret or the tilde), so whenever I do a npm install again, the same version of the dependency will be downloaded.&lt;/p&gt;

&lt;p&gt;Of course, doing this will require that you keep up-to-date with the dependencies that are likely to be updated often.&lt;/p&gt;

&lt;h1&gt;
  
  
  Wire up
&lt;/h1&gt;

&lt;p&gt;One of the reasons why Javascript is well adopted, is the flexibility on how to write code, it doesn't have an explicit convention on how to do it, but that can lead to technical debt when doing it, that's why I stick to some rules when working with Javascript, and also why you should do it too, the future yourself (or any developer you work with), will thank you for that.&lt;/p&gt;

&lt;p&gt;I presented you a small style guide (that hopefully will grow with the years) that I follow when working with React, you can use it, or twist at your convenience, whatever makes you feel happy when programming!&lt;/p&gt;

&lt;p&gt;Thanks for reading and happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>You really want to be a Senior??</title>
      <dc:creator>Cristofer</dc:creator>
      <pubDate>Mon, 11 Feb 2019 17:36:00 +0000</pubDate>
      <link>https://forem.com/christo_pr/you-really-want-to-be-a-senior-57g6</link>
      <guid>https://forem.com/christo_pr/you-really-want-to-be-a-senior-57g6</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fstp9ku9id1j5ey2v0adr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fstp9ku9id1j5ey2v0adr.jpg" alt="Programming Languages"&gt;&lt;/a&gt;&lt;br&gt;
&lt;sup&gt;&lt;sup&gt;&lt;sup&gt;&lt;sup&gt;&lt;sup&gt; several-programming-languages. viewed Feb 1 2019, &amp;lt; &lt;a href="https://www.kkeducationsociety.org.in/wp-content/uploads/2018/10/Programming-Language.png" rel="noopener noreferrer"&gt;https://www.kkeducationsociety.org.in/wp-content/uploads/2018/10/Programming-Language.png&lt;/a&gt; &amp;gt; &lt;/sup&gt;&lt;/sup&gt;&lt;/sup&gt;&lt;/sup&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Do you want to be a senior?
&lt;/h1&gt;

&lt;p&gt;Nowadays there's several programming languages for any purpose (web, analytics, cloud-computing, IA, ML, etc...), but even in this big 'era' where each week there's a &lt;a href="https://www.npmjs.com/what-is-npm" rel="noopener noreferrer"&gt;millions of new ways to solve the same issue&lt;/a&gt;, there are several people fighting each other to defend his own way to solve the problem.&lt;/p&gt;

&lt;p&gt;We all have this "hater" inside of us, we all like our own way to solve the problem (that's why we do it in first place), but why do we try to convince to other people that our way is the best way? Just because it has worked for us? i think this can be pretty selfish thinking&lt;/p&gt;

&lt;p&gt;I have learned across all my (little) career that &lt;strong&gt;sharing knowledge&lt;/strong&gt; is the best way how you can &lt;strong&gt;actually learn&lt;/strong&gt; something.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/5IqxJsqlCtkqc/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/5IqxJsqlCtkqc/giphy.gif" alt="Share knowledge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I always thought that a &lt;strong&gt;Senior&lt;/strong&gt; programmer was this mythical men, stackoverflow-less that always have a solution after been staring at the screen with pensive face  for like 10 seconds, but now i understand the real importance (i mean besides of all the mythical-men stuff) of this valuable person: &lt;strong&gt;MENTORING&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Help and let yourself help
&lt;/h1&gt;

&lt;p&gt;All start from the bottom, we all miss the &lt;code&gt;WHERE&lt;/code&gt; on the &lt;code&gt;DELETE&lt;/code&gt; statement, we all make the same silly mistakes that the people you call "noob" is making now, and just because you understand them now, doesn't mean all the people will magically catch up.&lt;/p&gt;

&lt;p&gt;Sometimes can be really annoying having someone right next to you asking you all about the project, but hey! if explain takes you some time, try understand, without any backup, a project that already has thousands of records and millions of lines of code?. Trust me, at the end of the day you'll get payoff with having someone that you can delegate work to&lt;/p&gt;

&lt;h1&gt;
  
  
  MENTORING === PATIENCE
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ARH12W5IVAbni/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ARH12W5IVAbni/giphy.gif" alt="impatient"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everything become easier when you understand it, but you need to be aware, and most important, never forget what it takes you to do it. Each time a person ask you something, is giving you his trust to help him to solve his misunderstanding, it's already shame enough for some people to ask, so there's no need to be rude when you're explaining something.&lt;/p&gt;

&lt;p&gt;I know sometimes it can be really hard to be patient (i mean, at the end of the day you're a senior, it's obvious that you have really important things to do), but helping will always be worth it, and you must find a way (normally people can wait) to make this happen.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a Senior?
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Besides all the normal task of a Senior Programmer, he/she must help &lt;em&gt;younger&lt;/em&gt; people to increase their level&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;What make's a programmer, Senior?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Years of Experience:&lt;/strong&gt; NO!, i honestly think this is not longer a fair measurement to take in count, i've seen so many people with poor years of experience but a really deep knowledge about what they are doing and vice versa&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solving real hard bugs:&lt;/strong&gt; is really likely that someone already had the problem you are having now, so is just matter of dig a little bit more to find the solution, although this is a great ability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Not use Google anymore:&lt;/strong&gt; you have a great memory, but we are talking about knowledge here&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Really long beard:&lt;/strong&gt; Hell no! although sometimes helps (visually 🤪)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's all about &lt;strong&gt;Responsibility&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You need to understand that no one but you is responsible for your own actions, if you make a "quick fix" that introduce technical debt in your code, be responsible when you have to refactor it once you have 10,000 rows inserted on your db per day, the same when you don't explain how to setup the project to the new guy on the team, be responsible when he start to adding all the spaghetti code to the repo.&lt;/p&gt;

&lt;p&gt;Once you start taking this with more seriousness, you'll be able to see what you are doing wrong.&lt;/p&gt;

&lt;h1&gt;
  
  
  Go for it!!
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/yoJC2K6rCzwNY2EngA/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/yoJC2K6rCzwNY2EngA/giphy.gif" alt="do it"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know all of this might sound really disturbing and we didn't get into this to teach people, but this is a win-win situation, and it actually works, you can see it all everywhere, communities, workshops, etc... they all share the same philosophy: &lt;strong&gt;Share and Grow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, do you still want to become a Senior?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1Z02vuppxP1Pa/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1Z02vuppxP1Pa/giphy.gif" alt="thanks"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>personal</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
