<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kurt Bauer</title>
    <description>The latest articles on DEV Community by Kurt Bauer (@krtb).</description>
    <link>https://dev.to/krtb</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%2F102491%2F450c2fec-49c8-4f23-a669-c9255414bb7b.jpg</url>
      <title>DEV Community: Kurt Bauer</title>
      <link>https://dev.to/krtb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/krtb"/>
    <language>en</language>
    <item>
      <title>CodeToday: "Word Split" Algorithm, Coderbyte</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Wed, 18 Mar 2020 19:22:03 +0000</pubDate>
      <link>https://dev.to/krtb/codetoday-word-split-algorithm-coderbyte-1gl</link>
      <guid>https://dev.to/krtb/codetoday-word-split-algorithm-coderbyte-1gl</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;I had worked on a Medium level Coderbyte challenge for an interview, but was unable to make any decent headway at the time. So I did what any reasonable person would do, let it bother me to the point that I made a codepen just to solve it.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Problem
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Problem: Have the function &lt;code&gt;WordSplit(strArr)&lt;/code&gt; read the array of strings stored in &lt;code&gt;strArr&lt;/code&gt;, which will contain 2 elements: the first element will be a sequence of characters, and the second element will be a long string of comma-seperated words, in alphabetical order, that represents a dictionary of some arbitrary length. For example: &lt;code&gt;strArr&lt;/code&gt; can be: &lt;code&gt;["hellocat", "apple, bat,cat,goodbye,hello,yellow,why"]&lt;/code&gt;. Your goal is to determine if the first element in the input can be split into two words, where both words in the dictionary that is provided in the second input. In this example, the firs element can be split into two words: hello and cat because both of those words are in the dictionary. Your program should return the two words that exist in the dictionary seperated by a comma. So for the example above, your program should return &lt;code&gt;hello, cat&lt;/code&gt;. There will only be one correct way to split the first element of characters into two words. If there is no way to split string into two words that exist in the dictionary, return the string not possible. The first element itself will never exist in the dictionary as a real word.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  My Solution
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;strArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;baseball&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;a,all,b,ball,bas,base,cat,code,d,e,quit,z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;// let strArr = ["hellocat", "apple,bat,cat,goodbye,hello,yellow,why"]&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;WordSplit&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="c1"&gt;// First Element, with single string   &lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;wordToCompare&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;strArr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;// Second Element, with single string   &lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;stringDictionary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;strArr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="c1"&gt;// Array of split strings   &lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;singleStrings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stringDictionary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;// Hold Answers   &lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;answerWords&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;

  &lt;span class="nx"&gt;singleStrings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;firstWord&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;let&lt;/span&gt; &lt;span class="nx"&gt;splitMainWordArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wordToCompare&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstWord&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;splitMainWordArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

      &lt;span class="nx"&gt;splitMainWordArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;word&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;let&lt;/span&gt; &lt;span class="nx"&gt;joinedWord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstWord&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;word&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reversedWord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;joinedWord&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;joinedWord&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;wordToCompare&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;reversedWord&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;wordToCompare&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
          &lt;span class="c1"&gt;// console.log(firstWord, word, 'winner')&lt;/span&gt;
          &lt;span class="nx"&gt;answerWords&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;firstWord&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;word&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Not Possible&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="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="nx"&gt;answerWords&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  The Process
&lt;/h1&gt;

&lt;p&gt;1) First I start by grabbing the 2 elements which the problem refers to. The variable &lt;code&gt;wordToCompare&lt;/code&gt; refers to the word that I'll be comparing. And the variable &lt;code&gt;stringDictionary&lt;/code&gt; represents the dictionary of words string that I was provided. &lt;/p&gt;

&lt;p&gt;2) In order to iterate over my dictionary string, I have to break it down with &lt;code&gt;stringDictionary.split(',')&lt;/code&gt; and assign that to a variable as well to late manipulate, named &lt;code&gt;singleStrings&lt;/code&gt;. It would look something like, &lt;code&gt;['a', 'all', 'b', ... ]'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3) I also add a variable called, &lt;code&gt;singleStrings&lt;/code&gt;, which will be an empty string for now. Later on we can set our answer to equal this variable to return our answer out of the loops.&lt;/p&gt;

&lt;p&gt;4) I then run a &lt;code&gt;map()&lt;/code&gt; function on the &lt;code&gt;singleStrings&lt;/code&gt; variable. This allows me to try and see if I can &lt;code&gt;split()&lt;/code&gt; my  &lt;code&gt;wordToCompare&lt;/code&gt; in order to see if I can split it into two words. The problem is that I then get an array of string elements. I now have to iterate over that array to check each string and see if it can be found in the original string in any way, like &lt;code&gt;baseball&lt;/code&gt; for example. &lt;/p&gt;

&lt;p&gt;5) Some of the loops result in single element arrays, but I only want to look at the ones with more than one, as we're trying to split my word into two elements. For this reason I add the &lt;code&gt;if(splitMainWordArray.length &amp;gt; 0)&lt;/code&gt; line.&lt;/p&gt;

&lt;p&gt;6) I add a second map function, &lt;code&gt;splitMainWordArray.map&lt;/code&gt;, to loop over the first arrays I got when I wrote &lt;code&gt;let splitMainWordArray = wordToCompare.split(firstWord)&lt;/code&gt;. I'm comparing the dictionary words saved  in the &lt;code&gt;singleStrings&lt;/code&gt; array and with my new arrays I'm creating each time I split a word. &lt;/p&gt;

&lt;p&gt;7) There was a case where I was getting &lt;code&gt;base&lt;/code&gt; from baseball, but I needed to place it inside an array to then run a &lt;code&gt;.join()&lt;/code&gt; and &lt;code&gt;.toString()&lt;/code&gt; in order for &lt;code&gt;ballbase&lt;/code&gt; to equal &lt;code&gt;baseball&lt;/code&gt;. Which is why I then write &lt;code&gt;if(joinedWord === wordToCompare || reversedWord === wordToCompare)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;8) If these 2 conjoined words are equal to our first string, &lt;code&gt;baseball&lt;/code&gt;, or if reversed they're equal, we then have our answer that we concatenate and return outside of all the loops by assigning it to the emprty &lt;code&gt;answerWords&lt;/code&gt; variable we created at the start.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I built this out in a &lt;a href="https://codepen.io/kurtbauer/pen/RwPyeRy?editors=1010"&gt;CodePen&lt;/a&gt; if you want to play around with it. The final answer I get from our example string was &lt;code&gt;base, ball&lt;/code&gt;. I kept trying to use &lt;code&gt;regex&lt;/code&gt; to solve the problem but lost time researching different ways I could use &lt;code&gt;match()&lt;/code&gt; or &lt;code&gt;replace()&lt;/code&gt;, but at the end of they day this is how I was more quickly able to solve the problem. If anyone can complete a simpler solution with a regular expression, I'd really love to take a look!&lt;/p&gt;

&lt;p class="codepen"&gt;
  &lt;span&gt;See the Pen &lt;a href="https://codepen.io/kurtbauer/pen/RwPyeRy"&gt;
  WordSplit&lt;/a&gt; by Kurt (&lt;a href="https://codepen.io/kurtbauer"&gt;@kurtbauer&lt;/a&gt;)
  on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/span&gt;
&lt;/p&gt;

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



</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>motivation</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>CodeToday: "Convert string to camel case" algorithm, CodeWars</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Mon, 16 Mar 2020 12:51:26 +0000</pubDate>
      <link>https://dev.to/krtb/codetoday-convert-string-to-camel-case-algorithm-codewars-5cbh</link>
      <guid>https://dev.to/krtb/codetoday-convert-string-to-camel-case-algorithm-codewars-5cbh</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;I started the morning working on an algorithm and realized it wasn't going to be a quick practice for me. I wanted to go over my thinking process, and the top solution after I submitted as well. We can always learn to be better, so why not try to think through someone's solution that seems cleaner? &lt;/p&gt;

&lt;h1&gt;
  
  
  The Problem
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;should handle empty values&lt;/li&gt;
&lt;li&gt;should remove underscores and convert first letter of word to upper case &lt;/li&gt;
&lt;li&gt;should remove hyphens and convert first letter of word to upper case&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  My Solution
&lt;/h1&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;toCamelCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;//console.log(str, 'testing')&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;containmentArea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;splitString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[^&lt;/span&gt;&lt;span class="sr"&gt;A-Z0-9&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/ig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="c1"&gt;//[ 'the', 'stealth', 'warrior' ]&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;containmentArea&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;splitString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;

   &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;word&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;splitString&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;splitWords&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;splitString&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;capitalLetter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;splitWords&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

     &lt;span class="nx"&gt;splitWords&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;capitalLetter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;joinedWord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;splitWords&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&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;containmentArea&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;joinedWord&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;newSentence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;containmentArea&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;containmentArea&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&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="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;h1&gt;
  
  
  The Process
&lt;/h1&gt;

&lt;p&gt;1) I'll have to check &lt;em&gt;if&lt;/em&gt; there's an empty string, so I create an if/else statement.&lt;br&gt;
2)  First I split my string, &lt;code&gt;splitString&lt;/code&gt;, with a regular expression&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;replace() = &lt;code&gt;searches a string for a specified value, or regular expression, and returns a new string where the specified values are replaced.&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;In this case I used a regular expression, &lt;code&gt;/[^A-Z0-9]/ig&lt;/code&gt;, in the search value.&lt;/li&gt;
&lt;li&gt;The carrot, &lt;code&gt;(^)&lt;/code&gt;, is the negation operator which matches anything NOT in the character class. Some great &lt;code&gt;regex&lt;/code&gt; resources are &lt;a href="https://www.regular-expressions.info/quickstart.html" rel="noopener noreferrer"&gt;Regular-Expressions.info&lt;/a&gt;, &lt;a href="https://www.regexpal.com/" rel="noopener noreferrer"&gt;RegexPal&lt;/a&gt; and this post on &lt;a href="https://stackoverflow.com/questions/1763071/negate-characters-in-regular-expression" rel="noopener noreferrer"&gt;StackOverflow&lt;/a&gt;. Below I pasted an example using the &lt;strong&gt;RegexPal&lt;/strong&gt; tool. Only characters that are not numbers or letters are being highlighted. Now we can see why it would find dashes in the strings I'm working on.&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%2F9luikug066x7jbe23f01.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%2F9luikug066x7jbe23f01.png" alt="REGEX"&gt;&lt;/a&gt;&lt;/p&gt;
Example of /[^A-Z0-9]/ig regex being used



&lt;p&gt;I replaced any odd characters, so that I could know for certain that all my words are separated by the same character. I know that all my words are separated by the underscore &lt;code&gt;_&lt;/code&gt;, so now it makes it easier for my to use the &lt;strong&gt;split() method&lt;/strong&gt; to separate each word by commas, and place them in an array, &lt;code&gt;[ 'the', 'stealth', 'warrior' ]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;3) My next big hurdle will be capitalizing every first letter of every word...except the first word. To deal with this I used the &lt;strong&gt;splice() method&lt;/strong&gt; to remove the first word from the original array, then push it into my &lt;strong&gt;containmentArea array&lt;/strong&gt;. I created an array to temp hold my strings, as I plan to later use the &lt;strong&gt;join() method&lt;/strong&gt; to smush them back into strings right before returning them. But there's still more work to be done. &lt;/p&gt;

&lt;p&gt;4) On to the for loop which I wrote with the &lt;strong&gt;ES6&lt;/strong&gt; syntax. Remember that &lt;code&gt;splitString&lt;/code&gt; is an array with my string split into comma separated elements. Let's start iterating through every element, using the variable &lt;code&gt;word&lt;/code&gt;. I will use the split method on every word, &lt;code&gt;splitString[word]&lt;/code&gt;, to further break down my string into something that would look like &lt;code&gt;&lt;br&gt;
[ 's', 't', 'e', 'a', 'l', 't', 'h' ]&lt;/code&gt;, for example &amp;amp; I'll store them in an array called &lt;code&gt;splitWords&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;5) I can than grab the first element in my &lt;code&gt;splitWords&lt;/code&gt; array with &lt;code&gt;splitWords[0]&lt;/code&gt;, and transform it with the the &lt;code&gt;toUppercase()&lt;/code&gt; method. This is how I capitalize every first letter of every word, except the first word that we &lt;code&gt;splice()&lt;/code&gt; -d off at the start of this algorithm.&lt;/p&gt;

&lt;p&gt;6) Since our process of transforming the first character in the string hasn't modified the original array, we'll have to do that with another &lt;code&gt;splice()&lt;/code&gt; method, only this time we'll have to supply our method with a third value, which will be what we want to replace our un-capitalized letter with. In this case, that's represented by the &lt;code&gt;capitalLetter&lt;/code&gt; variable in &lt;code&gt;splitWords.splice(0,1, capitalLetter)&lt;/code&gt;. And we then use our &lt;code&gt;join()&lt;/code&gt; method to squish our letters back together into one word, &lt;code&gt;['Stealth']&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;7) We still need to glue our camlCased sentence back together though. I write &lt;code&gt;containmentArea.push(joinedWord)&lt;/code&gt; to push our words with the first capitalized into our &lt;code&gt;containment&lt;/code&gt; array that still holds the first word we spliced off. And then use another joind, &lt;code&gt;let newSentence = containmentArea.join('')&lt;/code&gt; to create my camelCased sentence.&lt;/p&gt;

&lt;p&gt;8) We should be done at this point, but can't simply return the &lt;code&gt;containmanetArea&lt;/code&gt; variable that's holding our string. This is because the initial &lt;code&gt;split()&lt;/code&gt; we ran resulted in an array of strings, that was pushed into another array. So right before returning we use another &lt;code&gt;join()&lt;/code&gt; to condense our two arrays into one.&lt;/p&gt;

&lt;p&gt;This was my solution, and then after turning it in I am faced with this beautiful answer that's been voted as top:&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;toCamelCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

      &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;regExp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;-_&lt;/span&gt;&lt;span class="se"&gt;]\w&lt;/span&gt;&lt;span class="sr"&gt;/ig&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regExp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&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;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
       &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;1) The variable &lt;code&gt;regExp&lt;/code&gt; is set to equal a regular expression to find all word characters (Alphanumeric or underscore), which is the &lt;code&gt;\w&lt;/code&gt; portion of the regex. But with just that, you can't also highlight dashes. Which is why that symbol is proceeded by &lt;code&gt;[-_]&lt;/code&gt;, making an explicit statement that we want to match dashes and underscores. And as always, &lt;code&gt;i&lt;/code&gt; is to &lt;em&gt;ignore case&lt;/em&gt;, and &lt;code&gt;g&lt;/code&gt; is for &lt;em&gt;a global search&lt;/em&gt;. It's finding matches that when console logged to the screen would look like &lt;code&gt;-S match&lt;/code&gt; and &lt;code&gt;_s match&lt;/code&gt;; whis a (dash || underscore) + a (word character or number).&lt;/p&gt;

&lt;p&gt;2) The next step is calls for a replace method, which will take the item to replace in the first parameter, and in this case a call back function in the second parameter.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match. If pattern is a string, only the first occurrence will be replaced.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3) the &lt;code&gt;charAt()&lt;/code&gt; method takes an index:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An integer between 0 and 1-less-than the length of the string. If the index cannot be converted to the integer or no index is provided, the default is 0... &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just like an array, we're grabbing the second character at index 1, and transforming that to uppercase to replace the dash or underscore the preceded it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In just 3 steps someone was able to create a solution that was far easier to implement. Though this proves I need to brush up on my regular expressions, I'm glad I could break it down and understand every line. &lt;/p&gt;

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

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt" rel="noopener noreferrer"&gt;charAt()&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join" rel="noopener noreferrer"&gt;join()&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace" rel="noopener noreferrer"&gt;replace()&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice" rel="noopener noreferrer"&gt;splice()&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.regular-expressions.info/quickstart.html" rel="noopener noreferrer"&gt;Regular-Expressions.info&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.regexpal.com/" rel="noopener noreferrer"&gt;RegexPal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/1763071/negate-characters-in-regular-expression" rel="noopener noreferrer"&gt;Negate characters in Regular Expression&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alligator.io/js/for-of-for-in-loops/" rel="noopener noreferrer"&gt;ES6: for/in...for/of&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>todayilearned</category>
      <category>motivation</category>
    </item>
    <item>
      <title>CodeToday: Learning By Doing with React Hooks</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Thu, 12 Mar 2020 16:38:33 +0000</pubDate>
      <link>https://dev.to/krtb/codetoday-learning-by-doing-with-react-hooks-4kfb</link>
      <guid>https://dev.to/krtb/codetoday-learning-by-doing-with-react-hooks-4kfb</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;I haven't had a chance to implement React's state hooks in a project yet, so I quickly found a tutorial on &lt;a href="https://scotch.io/tutorials/build-a-react-to-do-app-with-react-hooks-no-class-components" rel="noopener noreferrer"&gt;Scotch.io&lt;/a&gt; to dive into.&lt;br&gt;
I wanted to document my journey through the project and questions I hit as I start using hooks.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Journey
&lt;/h1&gt;

&lt;p&gt;1) &lt;strong&gt;Question:&lt;/strong&gt; First question I had as I built the below code, was on the syntax. Specifically, using &lt;code&gt;useState([])&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Learn about React&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="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Meet friend for lunch&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="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Build really cool todo app&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Just some regular &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" rel="noopener noreferrer"&gt;destructuring&lt;/a&gt;, which "makes it possible to unpack values from arrays, or properties from objects, into distinct variables."&lt;/p&gt;

&lt;p&gt;I was used to object destructuring:&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wes&lt;/span&gt;&lt;span class="dl"&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;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 'Wes'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But with array destructuring, we don't have to worry about keys and values jumbling up our code. I quickly found a very clear post by &lt;a href="https://dev.to/sarah_chima"&gt;Sarah Chima&lt;/a&gt;, called &lt;a href="https://dev.to/sarah_chima/destructuring-assignment---arrays-16f"&gt;Destructuring Assignment in ES6- Arrays&lt;/a&gt;.&lt;br&gt;
Two key basic things are that this array destructuring helps in grabbing our elements &lt;strong&gt;based on the array's index&lt;/strong&gt;. And that &lt;strong&gt;commas&lt;/strong&gt; help us skip over elements and grab the next element.&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;var&lt;/span&gt; &lt;span class="nx"&gt;sentence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kurt&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;likes&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;programming&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;firstWord&lt;/span&gt;&lt;span class="p"&gt;,,&lt;/span&gt; &lt;span class="nx"&gt;lastWord&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sentence&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lastWord&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// programming&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now, when I map over my &lt;code&gt;todo&lt;/code&gt; array, the first element would look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// {text: "Learn about React"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, my app is displaying a list of todos&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%2Fv11mqternzklqs7m7xze.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%2Fv11mqternzklqs7m7xze.png" alt="todolist"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) &lt;strong&gt;Question:&lt;/strong&gt; How to add items to my list?&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;App&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;//useState: 2 variables, name them anything.&lt;/span&gt;
  &lt;span class="c1"&gt;// firstVar = value || this.state&lt;/span&gt;
  &lt;span class="c1"&gt;// secondVar = function to update value || this.setState&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;todos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Learn about React&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="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Meet friend for lunch&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="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Build really cool todo app&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&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;// spread operaotor = to create a copy of array&lt;/span&gt;
    &lt;span class="c1"&gt;// {text} = from TodoForm/form/input type=text&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newTodos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}];&lt;/span&gt; &lt;span class="c1"&gt;//needs to be object&lt;/span&gt;
    &lt;span class="nf"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// {text: "Learn about React"}&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;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;todo-list&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="nx"&gt;todos&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;todo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Todo&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;todo&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;TodoForm&lt;/span&gt; &lt;span class="nx"&gt;addTodo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;addTodo&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="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="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;&lt;strong&gt;Answer:&lt;/strong&gt; Where does the magic happen? Well first I had to create a TodoForm component. Still dealing with functional components and hooks, I just added the value for my variable, which will be blank at first. An onChange function was added into the input field, which then passes the value to the &lt;code&gt;addTodo&lt;/code&gt; function that we're getting from &lt;code&gt;App's&lt;/code&gt; state hook declaration. And finally we reset the value to be black with our &lt;code&gt;setValue&lt;/code&gt; function call that works in the same way as &lt;code&gt;setState&lt;/code&gt; does within Class components.&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;useState&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="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TodoForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;addTodo&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&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;handleSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;value&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="nf"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&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="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;form&lt;/span&gt; &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;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;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&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="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/form&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;TodoForm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then inside of our app, after importing our &lt;code&gt;TodoForm&lt;/code&gt;component, we pass it the &lt;code&gt;addToDo&lt;/code&gt; function as a prop. Let's take a look at that function. Here I'm pulling in the user's text, which is a property on our input field. I create a variable, and pass in a copy of my &lt;code&gt;todos&lt;/code&gt; array with the spread operator. The second variable in my array is the text we will adding onto our array, and thus our list of tasks.&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;addTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&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;// spread operaotor = to create a copy of array&lt;/span&gt;
    &lt;span class="c1"&gt;// {text} = from TodoForm/form/input type=text&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newTodos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}];&lt;/span&gt; &lt;span class="c1"&gt;//needs to be object&lt;/span&gt;
    &lt;span class="nf"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&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;3) &lt;strong&gt;Question:&lt;/strong&gt; How do I update my list once I've completed a task?&lt;/p&gt;

&lt;p&gt;Well most of the work for updating a task as complete is being done in the following callback function, inside my App.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;completedToDo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&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;// array holds copt of task list array&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newTodos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="c1"&gt;// find item by its index in array&lt;/span&gt;
    &lt;span class="c1"&gt;// access the isCompleted property&lt;/span&gt;

    &lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// set ToDo list to alrered array that was copied&lt;/span&gt;
    &lt;span class="nf"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&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;&lt;strong&gt;Answer:&lt;/strong&gt; It bothered me that I could only mark a task as complete once and not undo it according to the tutorial so I added a ternary to toggle my &lt;code&gt;isCompleted = false&lt;/code&gt; property that I added to all my task objects in their initial state. How this works is a &lt;code&gt;Todo&lt;/code&gt; component is created with the &lt;code&gt;completedToDo&lt;/code&gt; function. This function has access to the &lt;code&gt;index&lt;/code&gt; attribute. My &lt;code&gt;ToDo&lt;/code&gt; component now looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Todo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;completedToDo&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;// Set variabls to hold me strings here&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;complete&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Complete&lt;/span&gt;&lt;span class="dl"&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;undo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Undo&lt;/span&gt;&lt;span class="dl"&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;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;todo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;textDecoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;line-through&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="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="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&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;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&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="nf"&gt;completedToDo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &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="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;undo&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that I have an onClick even handler that registers when I click a task button, and sends the index up to my &lt;code&gt;completedToDo&lt;/code&gt; function. Depending on whether &lt;code&gt;todo.isCompleted&lt;/code&gt; if flase or true I display different text. Not a huge change, but it makes it feel more like a task list. It's in my &lt;code&gt;completedToDo&lt;/code&gt; function where I'm changing my boolean value. And then I'm using my react hook variable, &lt;code&gt;setTodos&lt;/code&gt;, to update my react hook state.&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;newTodos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;isCompleted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that's mainly it! Now we have buttons that can be marked as completed, or if we accidentally hit it or realize there was something missing, we can always &lt;code&gt;undo&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%2Fjcbly0tmvk4o2onm2bvb.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%2Fjcbly0tmvk4o2onm2bvb.png" alt="crossed out text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4) &lt;strong&gt;Question:&lt;/strong&gt; How can I delete an item from my list?&lt;/p&gt;

&lt;p&gt;Well it's basically a lot like the function I created to mark a task as completed.&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;removeTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;index&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;// create a copy of original array&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newTodos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="c1"&gt;// use splice() to remove item from array based on it's index&lt;/span&gt;
    &lt;span class="c1"&gt;// alters that copy of the array that we've made&lt;/span&gt;
    &lt;span class="nx"&gt;newTodos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setTodos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTodos&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;&lt;strong&gt;Answer:&lt;/strong&gt; We add this callback at a prop in our &lt;code&gt;ToDo&lt;/code&gt; component, it grabs the index, I create a copy of my &lt;code&gt;todos&lt;/code&gt; array, use the &lt;code&gt;splice()&lt;/code&gt; method to remove an element from our array based on it's  index. Then the new array copy with remove elements is set with &lt;code&gt;setTodos&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And that's pretty much it! Now both you and I understand the basic of using the &lt;code&gt;usState&lt;/code&gt; React Hook to add state to your functional components.&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%2Flnmc1kd5hs8o30ux93zh.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%2Flnmc1kd5hs8o30ux93zh.png" alt="Final List"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://scotch.io/tutorials/build-a-react-to-do-app-with-react-hooks-no-class-components" rel="noopener noreferrer"&gt;Scotch.io&lt;/a&gt; has some great tutorials, sometimes they can be outdated, but for the most part it's a great resource to have. Again, I didn't create this project, but wanted to talk through the parts I need to take a second to research. As you saw, hooks aren't that scary once you jump in! And a big thanks to &lt;a href="https://dev.to/sarah_chima"&gt;Sarah Chima&lt;/a&gt;, follow her for some more cool walk-troughs and tutorials!&lt;/p&gt;

&lt;p&gt;Oh and if you want to take a look at the coded version, I added a link to my &lt;a href="https://codesandbox.io" rel="noopener noreferrer"&gt;CodeSandbox&lt;/a&gt; I created. I also advise using that or &lt;a href="https://codepen.io" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt;, since with the free version you can create an infinite amount of public projects that can be fairly compartmentalized with different files/ NPM packages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/relaxed-keller-ddljg?fontsize=14&amp;amp;hidenavigation=1&amp;amp;theme=dark" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodesandbox.io%2Fstatic%2Fimg%2Fplay-codesandbox.svg" alt="Edit react-hooks-useState-intro"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>CodeToday: "Find Intersection" Algorithm, Coderbyte</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Mon, 09 Mar 2020 18:15:03 +0000</pubDate>
      <link>https://dev.to/krtb/codetoday-find-intersection-algorithm-coderbyte-1mg5</link>
      <guid>https://dev.to/krtb/codetoday-find-intersection-algorithm-coderbyte-1mg5</guid>
      <description>&lt;p&gt;&lt;a href="https://i.giphy.com/media/uT3hvuui47XUY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/uT3hvuui47XUY/giphy.gif" alt="Intersection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;I am constantly dealing with code, whether it be small algorithm exercises, creating projects for fun or work, or testing out new tech. Yet, I've realized that things start falling through the cracks once my Firefox browser hits around 55 open tabs. I do my best before pulling the emergency lever and save links to research later, but I know that with all the tools available I could be doing a better job of both helping others that may encounter the same problem, and documenting my small wins for future challenges.&lt;/p&gt;

&lt;p&gt;Not everything has to be worthy of 1k or more likes, and not everything has to be constructed to perfectly impress prospective employers or colleagues. Sometimes you just nerd out about code and you want to store that somewhere to reflect on down the road, maybe perfect, maybe not. &lt;/p&gt;

&lt;p&gt;Either way I think I've been too worried about someone being elitist or snobby about my learning, and I don't want that holding me back anymore. Maybe I come back and refactor my problems, maybe I don't. &lt;/p&gt;

&lt;p&gt;As always, I'm all for constructive comments or learning if you'd approach the problem differently.&lt;/p&gt;

&lt;p&gt;And that's okay! So after all of that intro into what I hope this series of constant posts will be, here's some of today's code!&lt;/p&gt;

&lt;h1&gt;
  
  
  The Problem Statement
&lt;/h1&gt;

&lt;p&gt;Below is the problem I found on &lt;strong&gt;Coderbyte&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Have the function FindIntersection(strArr) read the array of strings stored in strArr which will contain 2 elements: the first element will represent a list of comma-separated numbers sorted in ascending order, the second element will represent a second list of comma-separated numbers (also sorted). Your goal is to return a comma-separated string containing the numbers that occur in elements of strArr in sorted order. If there is no intersection, return the string false.&lt;/p&gt;

&lt;p&gt;For example: if strArr contains ["1, 3, 4, 7, 13", "1, 2, 4, 13, 15"] the output should return "1,4,13" because those numbers appear in both strings. The array given will not be empty, and each string inside the array will be of numbers sorted in ascending order and may contain negative numbers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  The Whiteboard
&lt;/h1&gt;

&lt;p&gt;Below are my initial impressions and notes, the brainstorming session which is much like the knockoff rumba currently banging itself into the walls of my living room. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3mJT1BDpTkrYGChS4u/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3mJT1BDpTkrYGChS4u/giphy.gif" alt="Roombas!"&gt;&lt;/a&gt;&lt;/p&gt;
Your brain when solving algorithms



&lt;ul&gt;
&lt;li&gt;my &lt;code&gt;strArr&lt;/code&gt; consists of two elements, which are each strings. So a simple map won't be so simple, so prior assembly required&lt;/li&gt;
&lt;li&gt;'(also sorted)' appears to mean that I won't have to worry about that&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return&lt;/code&gt;, a comma separated string, so I'll have to make sure not to keep my data in an array after working with it&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;if none, return false&lt;/code&gt;, means I need to check with an if/else somewhere&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  The Solution
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;FindIntersection&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;span class="c1"&gt;//1) Grab the first and second elements to be compared&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;strArr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;secondString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;strArr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;//2) Create empty arrays to store elements, after converted from strings to numbers&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstElementArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;secondElementArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="c1"&gt;//3) split() a string into an array of substrings&lt;/span&gt;
&lt;span class="c1"&gt;//4) map() calls the provided function once for each element in an array,&lt;/span&gt;
&lt;span class="c1"&gt;//in order, to iterate over each string element you want to covert to a&lt;/span&gt;
&lt;span class="c1"&gt;//number data type, and push to your array&lt;/span&gt;
&lt;span class="c1"&gt;//5) wrap each string element with Number(), to transform from string &lt;/span&gt;
&lt;span class="c1"&gt;//data type to number data type&lt;/span&gt;
  &lt;span class="nx"&gt;firstString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;oneNumber&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="nx"&gt;firstElementArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oneNumber&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="c1"&gt;//6) build the same function for the next element in the array of strings&lt;/span&gt;
  &lt;span class="nx"&gt;secondString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;oneNumber&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="nx"&gt;secondElementArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oneNumber&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;//7) create a variable to store list of numbers, called myAnswer&lt;/span&gt;
&lt;span class="c1"&gt;//8) use filter(), which creates an array filled with all array elements that pass a test&lt;/span&gt;
&lt;span class="c1"&gt;//9) create a test inside the filter function which uses includes(),&lt;/span&gt;
&lt;span class="c1"&gt;//which determines whether an array contains a specified element.&lt;/span&gt;
&lt;span class="c1"&gt;//Basically, is my secondElementArray element(e) included in my&lt;/span&gt;
&lt;span class="c1"&gt;//firstElementArray element(e) when compared?&lt;/span&gt;
&lt;span class="c1"&gt;//10) Wrap your returned answer inside a toString() method, &lt;/span&gt;
&lt;span class="c1"&gt;//which returns a string with all the array values, separated by commas&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myAnswer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;secondElementArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;firstElementArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;//11) Check to find if numbers are there, if not, return false&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;myAnswer&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;myAnswer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  The Retrospective
&lt;/h1&gt;

&lt;p&gt;No one is invincible, and no one is just born with a talent for coding. This is about always having a &lt;a href="https://www.psychologytoday.com/us/blog/click-here-happiness/201904/15-ways-build-growth-mindset"&gt;growth mindset&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here are some things that tripped me up and forced me to rethink my approach.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tried to just force map over my initial array, didn't realized that I had 2 strings to deal with&lt;/li&gt;
&lt;li&gt;I lost time trying to convert both strings in the first array, and then putting them into a single array. It was simpler for me to build to seperate functions. Though I believe I could just create a helper function and re-use to keep my code DRY.&lt;/li&gt;
&lt;li&gt;I searched for my &lt;code&gt;Number()&lt;/code&gt; method to convert my string elements&lt;/li&gt;
&lt;li&gt;I initially had my returned array and searched for my &lt;code&gt;toString()&lt;/code&gt; method&lt;/li&gt;
&lt;li&gt;I actually forgot to include a check if there were no matches, and re-read the question when writing this blog post! To be fair I had past the CoderByte tests without it and didn't realize...&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  The Conclusion
&lt;/h1&gt;

&lt;p&gt;I've written this out in a &lt;a href="https://codepen.io/kurtbauer/pen/LYVexjZ"&gt;CodePen Snippet&lt;/a&gt;, since I personally am more of a hands on learner, so here's to hoping this helps you in some way too.&lt;/p&gt;

&lt;p&gt;This is my first post in what I hope to be daily conversation and appreciation of coding that I find worth reflecting on. &lt;/p&gt;

&lt;p&gt;Imposter Syndrome and Anxiety are real things that deeply affect performance. I hope this motivates someone out there to keep a &lt;a href="https://www.psychologytoday.com/us/blog/click-here-happiness/201904/15-ways-build-growth-mindset"&gt;growth mindset&lt;/a&gt;, don't be afraid to write about something even if you don't feel like you know enough about it. It doesn't matter if it's not pretty or if you feel like you're "not a real programmer" because your solution isn't the cleanest. Put positive energy out there, be vulnerable, and always try to be your own best friend! We can all do this.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>todayilearned</category>
      <category>javascript</category>
      <category>motivation</category>
    </item>
    <item>
      <title>React Explained</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Thu, 07 Nov 2019 19:01:23 +0000</pubDate>
      <link>https://dev.to/krtb/react-explained-5gk</link>
      <guid>https://dev.to/krtb/react-explained-5gk</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;If you've ever taken a second to visit the &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; website, you've read their tagline...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A JavaScript library for building user interfaces&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  UI &amp;amp; state management are the main problems that React seeks to solve for front-end developers. This is the purpose of react.
&lt;/h4&gt;

&lt;p&gt;When interviewing for a front-end role or brushing up on concepts, we often scramble and open up over 100 tabs on our browser. I wanted to coalesce the main points that you would want to cover when talking about React to your peers.&lt;/p&gt;

&lt;p&gt;The following overview seeks to cover React's main concepts, which are important to understand in order to work efficiently.&lt;/p&gt;

&lt;p&gt;This is admittedly a long post, BUT it's meant to be more of a reference to get the most out of your reading time. I hope you enjoy it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's dive in! 🏊🏽‍♂️
&lt;/h2&gt;

&lt;p&gt;When building a JavaScript application, we expect to be working with data.&lt;/p&gt;

&lt;p&gt;Data in JS is usually built of primitive values, which include:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;numbers&lt;/li&gt;
&lt;li&gt;strings&lt;/li&gt;
&lt;li&gt;boolean &lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;li&gt;bigint&lt;/li&gt;
&lt;li&gt;symbols&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;As developer's we use these values at the lowest level of our app. These primitive values in JS are immutable, meaning they can't be changed. The variables holding them on the other hand can be reassigned new values.&lt;/p&gt;

&lt;p&gt;What does this mean to us as engineers, and foremost, as curious lovers of all things web?&lt;/p&gt;

&lt;h1&gt;&lt;center&gt;🤔&lt;/center&gt;&lt;/h1&gt;

&lt;p&gt;We need a way to manage our application's data, information that we gather and give to users, in a way that gives us the least amount of headache. As an engineer you are constantly weighing the pros and cons of solutions, do their efficiencies outweigh the readability and easy of use? You'll find that the answer to that question is constantly in flux.&lt;/p&gt;

&lt;p&gt;&lt;span id="index"&gt;For the following explanations, I'll be moving in the same order that React's own developers laid out concepts, with additional examples and break downs(🤘🏽) along the way.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/IMsOH8zBZBD6E/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/IMsOH8zBZBD6E/giphy.gif" alt="CHARGE"&gt;&lt;/a&gt;&lt;/p&gt;
Always forward, never backwards!



&lt;h2&gt;
  
  
  Main Concepts
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;JSX&lt;/li&gt;
&lt;li&gt;Rendering Elements&lt;/li&gt;
&lt;li&gt;Components &amp;amp; Props&lt;/li&gt;
&lt;li&gt;State &amp;amp; Lifecycle methods&lt;/li&gt;
&lt;li&gt;Handling Events&lt;/li&gt;
&lt;li&gt;Conditional Rendering&lt;/li&gt;
&lt;li&gt;Lists &amp;amp; Keys&lt;/li&gt;
&lt;li&gt;Forms&lt;/li&gt;
&lt;li&gt;Lifting State Up&lt;/li&gt;
&lt;li&gt;Composition VS Inheritance&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  1.&lt;strong&gt;J&lt;/strong&gt;-ava-&lt;strong&gt;S&lt;/strong&gt;-cript-&lt;strong&gt;X&lt;/strong&gt;-ml
&lt;/h1&gt;

&lt;p&gt;We should always strive to understand the basics. Though I personally understand most of the JavaScript aspect of JSX, I haven't particularly had to interact with XML too much. So my interest is peaked, what is XML?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction"&gt;XML&lt;/a&gt; stands for &lt;em&gt;Extensible Markup Language&lt;/em&gt;. And if you're thinking to yourself, "Kurt, X-M-L sounds a lot like H-T-M-L", well you're onto something. They're closely related! &lt;br&gt;
&lt;span id="jsx"&gt;&lt;/span&gt; &lt;br&gt;
The "extensible" piece is due to XML allowing you, as the developer, to define your own tags that can fit your own very specific needs. &lt;/p&gt;

&lt;p&gt;This aspect is super empowering and the developer's at Facebook who built React realized this as well.&lt;/p&gt;

&lt;p&gt;Okay, that was a lot of words but you're more of a visual learner. Let's look at some JSX code! 🔥⋔&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qwCc04bs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ovv5eypjgsyvhyelj3te.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qwCc04bs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ovv5eypjgsyvhyelj3te.png" alt="JSX"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What are we looking at above?
&lt;/h2&gt;

&lt;p&gt;Here we have what's known as a functional component, or "dumby component" due to it being best practice not to include much logic in these components.&lt;/p&gt;

&lt;p&gt;All we have is an anonymous arrow function assigned to our constant &lt;strong&gt;App&lt;/strong&gt;, which is then exported as a module by our &lt;em&gt;export default App&lt;/em&gt; statement.&lt;/p&gt;

&lt;p&gt;We'll get further into the App.js file in React, but for now understand that it's responsible for being the main source of truth along with our Index.js file that' located at the top level of our application's directory.&lt;/p&gt;

&lt;p&gt;Within our anonymous arrow function, we're returning a div element. Okay, so far so good, we've all handled div's before. But what's inside of our div?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PostList&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;👀&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Here we see a JSX element in the wild





&lt;p&gt;At the top of our app file, we're importing &lt;code&gt;PostList&lt;/code&gt; from a &lt;code&gt;PostList.js&lt;/code&gt; file, where our component lives. Thanks to the power of ES6 JS, we're able to use module imports to bring in the functionality we defined somewhere else. P Cool!&lt;/p&gt;

&lt;p&gt;To gain a more thorough mental image, let's look at the logic that we've abstracted away.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iDU3qigh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3o54qwp92f45sp221p8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iDU3qigh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3o54qwp92f45sp221p8j.png" alt="PostList"&gt;&lt;/a&gt;&lt;/p&gt;
PostList class component



&lt;p&gt;That's 44 lines of code we've abstracted away! Which makes it a lot easier to focus on the important things when working through our applications.&lt;/p&gt;

&lt;p&gt;JSX permits us to use XML-like tags, &lt;code&gt;&amp;lt;OurUniqueTag/&amp;gt;&lt;/code&gt;, to build the components and elements we use in React.&lt;/p&gt;

&lt;p&gt;Wait a second, it seems we haven't gone over components or elements yet. &lt;/p&gt;

&lt;p&gt;Let's start with elements, since components are built with elements!&lt;/p&gt;

&lt;h1&gt;
  
  
  2. const element = &lt;em&gt;Rendering Elements&lt;/em&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;span id="rendering"&gt;Similar to how primitive values are at the lowest level of the JavaScript language, &lt;a href="https://reactjs.org/docs/rendering-elements.html"&gt;"elements are the smallest building blocks of React apps."&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;


&lt;center&gt; DOM! DOM! DOM! &lt;/center&gt;
&lt;br&gt;
&lt;img src="https://i.giphy.com/media/C2JDmUOWRp6tq/giphy.gif" alt="DOM"&gt;In my defense, 'Fast &amp;amp; The Furious' came up on GIPHY when I searched DOM



&lt;p&gt;Why did I suddenly starting talking about DOM? Building blocks, it's alllll about building blocks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction"&gt;DOM&lt;/a&gt; stands for &lt;strong&gt;"DocumentObjectModel"&lt;/strong&gt;, and like a graphical user interface, it's a programing interface for HTML and XML.&lt;/p&gt;

&lt;p&gt;It isn't the web page, but instead it's a representation of it, to allow you to magically wave your developer wand 🧙🏽‍♂️ and change document structure, style, and content.&lt;/p&gt;

&lt;p&gt;The data structs that the DOM uses to allow programming languages to connect to the page, are nodes and objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;ReactDOM&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-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;ReactDOM&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you've developed with react you've had to wrap your &lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; with ReactDOM's render method.&lt;/p&gt;

&lt;p&gt;To show our users of the web cool sites that do something, we have to constantly be updating our DOM. These dynamic updates can have their own buggy behavior though. &lt;/p&gt;

&lt;p&gt;On an update, your browser has to refresh CSS, refresh the DOM node tree and ultimately refreshes the screen that's being displayed. Before React, we'd write a lot of JavaScript code to do this heavy lifting, and if you weren't too careful, it'd start to get noticeable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/8heqZXlz6ylZS/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/8heqZXlz6ylZS/giphy.gif" alt="RUPAUL"&gt;&lt;/a&gt;&lt;/p&gt;
How my friend and I looked the first time we spent a week writing a bunch of JS only to see our web page lag us to death



&lt;p&gt;Our JSX elements represent DOM elements, and upon being rendered by ReactDOM.render(), are parsed into those elements on a webpage.&lt;/p&gt;

&lt;p&gt;When React is initially rendering elements, it also is building a 'tree' that &lt;strong&gt;represents&lt;/strong&gt; the DOM, or &lt;em&gt;current tree&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reconciliation&lt;/strong&gt; is actually an advanced React concept we've managed to stick in here. You can find more in &lt;a href="https://reactjs.org/docs/reconciliation.html"&gt;React's docs&lt;/a&gt;, though we'll talk about it a bit here. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When diffing two trees, React first compares the two root elements. The behavior is different depending on the types of the root elements.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As updates are made that tell React to re-render, or refresh, a second &lt;em&gt;workInProgress&lt;/em&gt; tree is created, to represent what the DOM &lt;em&gt;will&lt;/em&gt; be. After processing the &lt;code&gt;workInProgress&lt;/code&gt; updates for the DOM, the &lt;code&gt;currentTree&lt;/code&gt; will &lt;strong&gt;reconcile&lt;/strong&gt; any differences.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;And here is the advantage to using React, performance optimization. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The performance of your app on the web is optimized by two key aspects of this process&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grouping DOM Updates

&lt;ul&gt;
&lt;li&gt;React waits until all updates are processed before    placing them in the workInProgress tree.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Selective Updates

&lt;ul&gt;
&lt;li&gt;React has the ability to apply a diffing algorithm to rapidly select what data needs updating.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let's pivot back over to components 🏃🏽‍♂️&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Components &amp;amp; Props
&lt;/h1&gt;

&lt;p&gt;&lt;span id="components"&gt;In our above code snippet,  was a component that we imported, composed of JSX elements.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;We saw the 44 lines of code that were able to be abstracted away from our App file. Components like this allow us to split up the user interface in reusable building blocks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen." -React Docs&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="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;Comment&lt;/span&gt; &lt;span class="o"&gt;=&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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Comment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserInfo&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;author&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Comment-text&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="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Comment-date&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="nx"&gt;formatDate&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="nx"&gt;date&lt;/span&gt;&lt;span class="p"&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="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;In this component, we're passing &lt;code&gt;props&lt;/code&gt; as an argument to our array function.&lt;/p&gt;

&lt;p&gt;Props, or properties, are data objects that traverse the React node tree, in order to provide components with the information they need to &lt;code&gt;repaint&lt;/code&gt; the browser DOM.&lt;/p&gt;

&lt;p&gt;But where do these props come from? To understand that, we should take a minute to look at state.&lt;/p&gt;

&lt;h1&gt;
  
  
  4. State and Lifecycle
&lt;/h1&gt;

&lt;p&gt;In our React applications, we will often set initial state in an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PREFERRED &amp;amp; COMMON WAY&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="na"&gt;isClicked&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;initialGreeting&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello, there!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//OR BUILT WITH A CONSTRUCTOR&lt;/span&gt;

&lt;span class="kd"&gt;constructor&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="k"&gt;super&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="k"&gt;this&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="na"&gt;isClicked&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;initialGreeting&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello, there!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;span id="state"&gt;Your state should be sitting within a class component, which typically looks like the code below.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Below is an example of a class react component instance. The difference between a &lt;code&gt;class&lt;/code&gt; component and a &lt;code&gt;functional&lt;/code&gt;, component which is at it's core purely an arrow function, is that a React Class component comes prepackaged with &lt;strong&gt;lifecycle&lt;/strong&gt; methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Clock&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;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;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="c1"&gt;// Here's some text!&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is also the reason why developers may choose to call class components, "smart components" and functional components, "dumb components". Our class component is where we will attempt to relay all of our logic, and functional components are more so containers or used for simple building blocks.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But what are &lt;strong&gt;lifecycle methods&lt;/strong&gt;?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When React starts it's work, the first thing it's going to look at is your component's state, when your component is a class component. React won't use up resources looking at dumby components.&lt;/p&gt;

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

&lt;p&gt;You can give your state default values to start the app with, as we've already seen in our examples, or pass in props if you'd like. The preferred approach is to use a simple state object, over using a constructor. Though constructor's can come in handy when creating refs or method binding. But that's a different conversation.&lt;/p&gt;

&lt;p&gt;Let's list our the lifecycle methods currently available to us with some brief descriptors.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;componentDidMount()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;after initial render, method is called&lt;/li&gt;
&lt;li&gt;used to load/set data&lt;/li&gt;
&lt;li&gt;makes sure that before we send of an AJAX request, there's actually a component for it to be rendered on&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;shouldComponentUpdate(nextProps, nextState)&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;only update a component IF the props it needs change&lt;/li&gt;
&lt;li&gt;issues: will not allow your component to update regularly &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;componentDidUpdate(prevProps, prevState, snapshot)&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;this allows us to work with committed changes to the current DOM tree we reviewed earlier when looking at the DOM&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;componentWillUnmount&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;according to React docs: "it’s very important to free up resources taken by the components when they are destroyed."&lt;/li&gt;
&lt;li&gt;this method is mostly used for cleaning out leftover behavior that's consuming vital app resources&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Oof, that was a lot, and there are other helpful ones like &lt;code&gt;getSnapshotBeforeUpdate&lt;/code&gt;, &lt;code&gt;getDerivedStateFromError&lt;/code&gt;, &lt;code&gt;componentDidCatch&lt;/code&gt;, and &lt;code&gt;getDerivedStateFromProps&lt;/code&gt; that you should take some time to look at. But the methods mentioned in our list are the main ones you'll be needed to build a nice application.&lt;/p&gt;

&lt;p&gt;Main take away is that these lifecycle methods allow us to update out apps data, or state. &lt;/p&gt;

&lt;h2&gt;
  
  
  The 3 Main Rules of State
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Do not modify state directly

&lt;ul&gt;
&lt;li&gt;this.state.comment = "nopity-nope nope"&lt;/li&gt;
&lt;li&gt;this.setState({words: "better!"})&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;State updates can be Asynchronous

&lt;ul&gt;
&lt;li&gt;remember to use a form of setState that accepts a function, over an object.&lt;/li&gt;
&lt;li&gt;this.setState((state, props) =&amp;gt; ({words: state.words}))&lt;/li&gt;
&lt;li&gt;can also be a regular function&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;State Updates are Merged 

&lt;ul&gt;
&lt;li&gt;your updated state is merged into the current node tree, and then you can setState({}) in as many locations and as many times as you'd like.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember: in React, data flows downwards. Think of waterfalls, made up state in parent components that is channeled downwards to their children by props.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  5. Handling 🖐🏽 Events
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Describing Event Handlers
&lt;/h3&gt;

&lt;p&gt;&lt;span id="handling"&gt;The nice thing about this section is that there's not a lot of brain stretching needed. Events in react are for the most part handled similarly to regular JS events.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Mainly we should consider the syntactic sugar used to describe our React events. The main thing to remember is that they're camelCased.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Regular JS event

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;button onclick="rainDownMoney()"&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;React Event Handler

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;button onClick={this.raindDownMoney}&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Synthetic Events
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;"Your event handlers will be passed instances of SyntheticEvent, a cross-browser wrapper around the browser’s native event. It has the same interface as the browser’s native event, including stopPropagation() and preventDefault(), except the events work identically across all browsers" - React Docs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Event Pooling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Key Note: you can't access Synthetic events in an async fashion

&lt;ul&gt;
&lt;li&gt;due to &lt;strong&gt;Event Pooling&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;this means that your SyntheticEvent object is reused in order to improve performance.&lt;/li&gt;
&lt;li&gt;the properties attached to your synthetic event become null after your callback function is triggered. &lt;/li&gt;
&lt;li&gt;&lt;code&gt;event.persist()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;will allow you access to event props in an async way.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Binding JS's THIS in React
&lt;/h3&gt;

&lt;p&gt;In JavaScript, class methods aren't bound to their THIS value. Now, whole days are spent at bootcamps reviewing and drilling down this concept. But let's take a crack at a quick overview.&lt;/p&gt;

&lt;p&gt;From &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind"&gt;MDN&lt;/a&gt; on &lt;code&gt;Function.prototype.bind()&lt;/code&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The simplest use of bind() is to make a function that, no matter how it is called, is called with a particular this value. A common mistake for new JavaScript programmers is to extract a method from an object, then to later call that function and expect it to use the original object as its this (e.g. by using that method in callback-based code). Without special care, however, the original object is usually lost. Creating a bound function from the function, using the original object, neatly solves this problem:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E5KakMha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6wbec06zbrfa3c7bab25.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E5KakMha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6wbec06zbrfa3c7bab25.png" alt="BIND"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above example is from MDN, what we should take away from this is that the global "window" object &amp;amp; scope come into play here. &lt;/p&gt;

&lt;p&gt;Our function retrieveX() is being invoked in the global scope, and this deriving it's value for &lt;code&gt;module.getX&lt;/code&gt; from &lt;code&gt;this.x = 9&lt;/code&gt; that was defined at the top of the file. Instead of the x inside of our module object.&lt;/p&gt;

&lt;p&gt;Solution: retrieveX.bind(module)&lt;/p&gt;

&lt;p&gt;Binding this allows us to fix the THIS values to the ones we want.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;This&lt;/code&gt; is determined by how functions are called during the runtime binding or association of our variables, functions and data. &lt;code&gt;This&lt;/code&gt; will always default to the global object, or window in a browser. Which trust me, if you forget to bind, will clearly be seen as an error in the console.&lt;/p&gt;

&lt;h3&gt;
  
  
  Two ways to bind this
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Public Class Fields syntax (experimental)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;LoggingButton&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;handleClick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
  &lt;span class="c1"&gt;// EXPERIMENTAL &lt;/span&gt;
  &lt;span class="nx"&gt;handleClick&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this is:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&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="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;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&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;handleClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Arrow Functions!
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;LoggingButton&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;handleClick&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this is:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&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="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;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;handleClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Events and the binding of this can lead to most of your bugs when you're starting out with React, and even later down the line if you forget to bind. I've mixed up my arrow functions with my public class field syntax before, so best to pick one and stick to it through your app.&lt;/p&gt;

&lt;h1&gt;
  
  
  6. ✅ Conditional Rendering ❌
&lt;/h1&gt;

&lt;p&gt;&lt;span id="conditional"&gt;Remember how using components allowed us to have less code cluttering up our files? Conditional rendering, or displaying elements based on the state/props of your app, allows us to write less code and make it more clear.&lt;/span&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;LoginControl&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="kd"&gt;constructor&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;super&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleLoginClick&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;handleLoginClick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&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;handleLogoutClick&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;handleLogoutClick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&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;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleLoginClick&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&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;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleLogoutClick&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&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;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;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="nx"&gt;isLoggedIn&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LogoutButton&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&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;handleLogoutClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LoginButton&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&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;handleLoginClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&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;Greeting&lt;/span&gt; &lt;span class="nx"&gt;isLoggedIn&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&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="nx"&gt;button&lt;/span&gt;&lt;span class="p"&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LoginControl&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&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;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding expressions to JSX
&lt;/h3&gt;

&lt;p&gt;There are a couple of cool ways to add logic into your JSX&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inline IF with logical &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator

&lt;ul&gt;
&lt;li&gt;IF condition &lt;code&gt;true&lt;/code&gt;, element after &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; renders&lt;/li&gt;
&lt;li&gt;IF condition &lt;code&gt;false&lt;/code&gt;, ignore
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&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;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;       &lt;span class="c1"&gt;// start of condition&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;unreadMessages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; 

          &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;have&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;unreadMessages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;unread&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="c1"&gt;// end of condition&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;IF-Else ternary(takes 3 operands) operator

&lt;ul&gt;
&lt;li&gt;condition ? return if true : return if false
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&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="c1"&gt;// start of condition&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;isLoggedIn&lt;/span&gt; &lt;span class="p"&gt;?&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;LogoutButton&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&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;handleLogoutClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;        &lt;span class="p"&gt;:&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;LoginButton&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&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;handleLoginClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;)
&lt;/span&gt;       &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="c1"&gt;// end of condition&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;If you want nothing to occur if your condition is false, you can also always swap in a &lt;code&gt;null&lt;/code&gt; primitive value.&lt;/li&gt;
&lt;li&gt;this won't affect lifecycle methods&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  7. Lists 📝 and Keys 🔑
&lt;/h1&gt;

&lt;p&gt;&lt;span id="lists"&gt;There's two solid points you should understand about building lists.&lt;/span&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Displaying a list of items is usually done with the help of the &lt;code&gt;map()&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;Elements being mapped over need unique keys, but they don't need to be globally unique.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;NumberList&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="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;numbers&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;listItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ListItem&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;
              &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;number&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="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;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="c1"&gt;// if we watned to make things look messy&lt;/span&gt;
      &lt;span class="c1"&gt;// we could also directly embed &lt;/span&gt;
      &lt;span class="c1"&gt;// our functioninside &lt;/span&gt;
      &lt;span class="c1"&gt;// of the brackets&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;listItems&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&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;h1&gt;
  
  
  8. Forms
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Controlled Components

&lt;ul&gt;
&lt;li&gt;in regurlar HTML forms&lt;/li&gt;
&lt;li&gt;elements like (input, textArea, select) maintain their own state&lt;/li&gt;
&lt;li&gt;the react way&lt;/li&gt;
&lt;li&gt;mutable state kept in state prop, updated by &lt;code&gt;setState()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Issue

&lt;ul&gt;
&lt;li&gt;React should be in charge of being our &lt;code&gt;singl source of truth&lt;/code&gt; when it comes to data. Above we see that there's two different sets battling it out. Let's combine them with the help of our controlled component.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Handler functions
&lt;/h3&gt;

&lt;p&gt;&lt;span id="forms"&gt;It doesn't affect the function if you name it something else, but it's common practice to name it by what it does, like &lt;code&gt;handleSubmit()&lt;/code&gt;. The component is controlled because we set initial state with our constructor, and alter it with our own onChange event handler, that triggers the function we defined to &lt;code&gt;setState()&lt;/code&gt; based on a condition we defined. Thus, we have the control.&lt;/span&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;NameForm&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="kd"&gt;constructor&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;super&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="k"&gt;this&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="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&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;handleChange&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;handleChange&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&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;handleSubmit&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;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A name was submitted: &lt;/span&gt;&lt;span class="dl"&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&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="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;form&lt;/span&gt; &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&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;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Name&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;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;text&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="p"&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&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;handleChange&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="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;submit&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;Submit&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;/form&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  9. Lifting State Up
&lt;/h1&gt;

&lt;p&gt;&lt;span id="lifting"&gt;This was another area where the learning curve is steep and the trek up the hill is difficult. But eventually things start to add up, especially if you've spent a good amount of time reading over the docs. &lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Here are the basic steps to follow when dealing with lifting state up from a child component to it's immediate parent.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define a function in your parent component&lt;/li&gt;
&lt;li&gt;pass that to your child component as a function&lt;/li&gt;
&lt;li&gt;pass in the changed state from your child component to the prop, which contain's the parent's function, so that data traverses your node tree all the way back up to your one source of truth&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  10. Composition VS Inheritance 🥊
&lt;/h1&gt;

&lt;p&gt;&lt;span id="composition"&gt;The react team doesn't say one is better than the other, so to clarify we're not going to say that either. But what is recommended by the team that built react, is to use composition in most cases, and inheritance in rare ones. These are architectural methodologies, relevant to our parent and child components. &lt;/span&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;INHERITANCE (extending properties from parent class)

&lt;ul&gt;
&lt;li&gt;in Object Oriented languages, this is when the child class obtains properties from it's parent class.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;COMPOSITION (referencing objects in other class instances)

&lt;ul&gt;
&lt;li&gt;describes a class that references objects of another class, as instances.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The Point?

&lt;ul&gt;
&lt;li&gt;Code reuse&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's take a look at some examples from &lt;a href="https://programmingwithmosh.com/react/react-composition-vs-inheritance/"&gt;Mosh Hamedani&lt;/a&gt;, an awesome React developer and blogger. I highly recommend you take a look at more of his stuff.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//PARENT&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Heading&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;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;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;h1&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;this&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="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;       &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/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="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;propTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;defaultProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Heading One&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//CHILD #1&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ScreenOne&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;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;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;Heading&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Custom Heading for Screen One&lt;/span&gt;&lt;span class="dl"&gt;'&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="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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// CHILD #2&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ScreenTwo&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;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;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;Heading&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Custom Heading for Screen Two&lt;/span&gt;&lt;span class="dl"&gt;'&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="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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What we see here is that we define a parent component, which relies on incoming props to update. This is a customizable value, that can be changed depending on the child that displays it. If the props change, so do the messages that get displayed.&lt;/p&gt;

&lt;p&gt;Below is an &lt;a href="https://www.tutorialspoint.com/composition-vs-inheritance-in-react-js"&gt;example&lt;/a&gt; of inheritance, without getting too detailed, inheritance extends props from parent components. But things can get complicated and complex.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CreateUserName&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;UserNameForm&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="nx"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;super&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="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="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;parent&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;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Create&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;         &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Stick with the composition methodology and you should be fine.&lt;/p&gt;


&lt;center&gt;Back To Index&lt;/center&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l3UcjOy67y3JeCGY0/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l3UcjOy67y3JeCGY0/giphy.gif" alt="CHECKPOINT"&gt;&lt;/a&gt;&lt;/p&gt;
Congrats! We made it!



&lt;p&gt;Grrrreat, we reached the end! There are other exciting concepts like Context, more on &lt;code&gt;HigherOrderComponents&lt;/code&gt;, and &lt;code&gt;Hooks&lt;/code&gt; that I'll be covering in different posts. But that doesn't make them any less important. I hope this post was able to demystify a lot of the bugs you've encountered when working with React.   &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Rails 6 is out, should I upgrade and start re-learning now?</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Fri, 27 Sep 2019 15:26:30 +0000</pubDate>
      <link>https://dev.to/krtb/rails-6-is-out-should-upgrade-and-start-re-learning-now-3de2</link>
      <guid>https://dev.to/krtb/rails-6-is-out-should-upgrade-and-start-re-learning-now-3de2</guid>
      <description>&lt;p&gt;&lt;a href="https://i.giphy.com/media/3WuYdwUHEAeMqfcJh2/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3WuYdwUHEAeMqfcJh2/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It was brought to my attention this morning that the new version of Rails was released, currently &lt;a href="https://weblog.rubyonrails.org/releases/"&gt;Rails 6.0: Action Mailbox, Action Text, Multiple DBs, Parallel Testing, Webpacker by default, and Zeitwerk&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I had started a project with rails 5 not so long ago. Should I lose the progress I was making and turn in a different direction?&lt;/p&gt;

&lt;p&gt;What's the best practice when a new version of a framework or language is released? How long should I wait before putting in the work to update myself and my projects?&lt;/p&gt;

&lt;p&gt;A friend and Rails developer mentioned that it depends, but I'm unsure as to what it depends on. Should I do it if my focus is proving that I'm competent in a technology? Or only if a work project demands it? &lt;/p&gt;

&lt;p&gt;My concern is that I'll be focusing on something that isn't a priority or pivotal to many employers. I'm not saying I don't want to learn, but I am saying I don't want to lose time on something that isn't a priority to other developers I'd be working with or under. I'd still build a project with it to learn, just at a slower pace. &lt;/p&gt;

&lt;p&gt;I do know that many companies delay upgrading due to dependencies. So what does everyone else think? Getting some feedback would be greatly appreciated, looking forward to any thoughts on the subject.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How long do you wait before learning a new version of a language or framework?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thanks in advance and sorry if this has been asked here before!&lt;/p&gt;

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

</description>
      <category>discuss</category>
      <category>ask</category>
      <category>rails</category>
      <category>help</category>
    </item>
    <item>
      <title>Installing psql(11.5) with hombrew, setting up PgAdmin and Postgres.app</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Wed, 18 Sep 2019 19:02:10 +0000</pubDate>
      <link>https://dev.to/krtb/installing-psql-11-5-with-hombrew-setting-up-pgadmin-and-postgres-app-5gio</link>
      <guid>https://dev.to/krtb/installing-psql-11-5-with-hombrew-setting-up-pgadmin-and-postgres-app-5gio</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;I've been going through and cleaning up my system, updating the tools, frameworks and languages that I have installed on my local machine.&lt;/p&gt;

&lt;p&gt;While doing this, I realized I had never installed postgresql through the package manager, Homebrew. And since as of this moment, I don't have any critical projects using my local setup, I decided to go through the pain of setting up things right once, so that I don't have to worry about it in the future when wanting to easily update or remove any packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Why
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt; is like NPM or Rbvm in the sense that it's a package manager, meant to help you easily update, remove, or add packages. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple's macOS operating system and Linux. The name is intended to suggest the idea of building software on the Mac depending on the user's taste. Originally written by Max Howell, the package manager has gained popularity in the Ruby on Rails community and earned praise for its extensibility.[3] Homebrew has been recommended for its ease of use[4] as well as its integration into the command line.[5] Homebrew is a non-profit project member of the Software Freedom Conservancy, and is run entirely by unpaid volunteers.[6] - per &lt;a href="https://en.wikipedia.org/wiki/Homebrew_%28package_management_software%29"&gt;wikipedia&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The How
&lt;/h2&gt;

&lt;p&gt;First I needed to figure out how to delete my original install that's not through Homebrew.&lt;/p&gt;

&lt;p&gt;Let's back things up&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3oFzlVGQcWiBp9Kcve/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3oFzlVGQcWiBp9Kcve/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
NSFPW: not safe for puppy work





&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt; 🜲  pg_dump &lt;span class="nt"&gt;-d&lt;/span&gt; informo-backend_development &lt;span class="nt"&gt;-n&lt;/span&gt; public &lt;span class="nt"&gt;-f&lt;/span&gt; informee-backend.sql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you have your back up of a singular database.&lt;br&gt;
We can worry about this later on, when we need to import it back.&lt;br&gt;
But for now, we can celebrate that we did one thing right, hurrrray!&lt;/p&gt;

&lt;p&gt;Next, uninstalling postgresql from your machine. We should check which version of psql you have installed using the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;psql &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="nt"&gt;-version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Mine was 10.10 so I then ran the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;open /Library/PostgreSQL/10.10/uninstall-postgresql.app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But I got an error that said I didn't have that installed there.&lt;br&gt;
I took a short cut and used my &lt;a href="https://freemacsoft.net/appcleaner/"&gt;AppCleaner&lt;/a&gt; app that located where all the files where after dragging and dropping my app. Also as a side note, I ended up getting the yearly subscription for &lt;a href="https://macpaw.com/"&gt;CleanMyMac X&lt;/a&gt; after diving in to see if there was a better alternative.&lt;/p&gt;

&lt;p&gt;Always run &lt;code&gt;brew update&lt;/code&gt; before installing and then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;after which you can run &lt;code&gt;which psql&lt;/code&gt; to check the version that was installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Issues Log
&lt;/h2&gt;

&lt;p&gt;Here's areas where I ran into problems&lt;/p&gt;

&lt;p&gt;1) Adding the &lt;a href="https://postgresapp.com/"&gt;Postgress App&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I downloaded the app after installing the latest psql version through homebrew, I kept getting an error stating &lt;code&gt;Binaries not found&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I thought it was a million things like, I had deleted the wrong core files, installed in the wrong place due to homebrew, etc. I wondered if it was even possible to run the app alongside the homebrew installation r if I was just going got have to default to using the installer like a noob.&lt;/p&gt;

&lt;p&gt;After much searching through stackoverflow and the like, I found this &lt;br&gt;
 &lt;a href="https://github.com/PostgresApp/PostgresApp/issues/399"&gt;Upgrading from pre 9.5 instructions are not clear #399&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which all grunting aside was pretty great, I realized I had to click the side tab and the create a new server. That was it! Apparently the default server it came with was pointing to the psql -v 10 and I need 11, which creating a brand new server solved.&lt;/p&gt;

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



&lt;p&gt;2) Setting up &lt;a href="https://www.pgadmin.org/"&gt;PgAdmin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The core of the issue was this, after installing, opening a new window and entering my default password, I went ahead and tried adding my server. Thankfully, this stackoverflow post helped me &lt;a href="https://stackoverflow.com/questions/16889400/pgadmin-and-postgresql-cant-connect-to-server"&gt;pgAdmin and PostgreSQL: can't connect to server&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But everytime I entered my hostname, and the server name, I got a &lt;code&gt;connection refused&lt;/code&gt; error.&lt;/p&gt;

&lt;p&gt;Okay let's open up the database from the Postgress App we just got working.&lt;/p&gt;

&lt;p&gt;Click on a database and a terminal window opens. You're in the matrix.&lt;/p&gt;

&lt;p&gt;Now we type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="n"&gt;port&lt;/span&gt; 
&lt;span class="c1"&gt;------&lt;/span&gt;
 &lt;span class="n"&gt;my_port_number_here&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Cooool. How about the host name?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="n"&gt;listen_addresses&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="n"&gt;listen_addresses&lt;/span&gt; 
&lt;span class="c1"&gt;------------------&lt;/span&gt;
 &lt;span class="n"&gt;localhost&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Oh, I was using my machine name and not the &lt;code&gt;localhost&lt;/code&gt;...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/eBCnpuRGBhQGY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/eBCnpuRGBhQGY/giphy.gif" alt="ded"&gt;&lt;/a&gt;&lt;/p&gt;
Don't mind me, just going around in circles with myself



&lt;p&gt;Once I added the correct info, the database gates opened and I had my db's showing on the page.&lt;/p&gt;

&lt;p&gt;Below I've added two other links that would be helpful in getting setup, &lt;a href="https://gist.github.com/Atlas7/b1a40a2ffd85728b33e7"&gt;remove_postgres_on_mac_os.md&lt;/a&gt; and &lt;a href="https://dataschool.com/learn-sql/how-to-start-a-postgresql-server-on-mac-os-x/"&gt;"how to start a postgresql server on macos"&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@davidclode?utm_medium=referral&amp;amp;utm_campaign=photographer-credit&amp;amp;utm_content=creditBadge" rel="noopener noreferrer" title="Download free do whatever you want high-resolution photos from David Clode"&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;David Clode&lt;/span&gt;&lt;/a&gt; on Unsplash&lt;/p&gt;

</description>
      <category>terminal</category>
      <category>backend</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Guess That Tech!</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Wed, 11 Sep 2019 14:48:43 +0000</pubDate>
      <link>https://dev.to/krtb/guess-that-tech-47lk</link>
      <guid>https://dev.to/krtb/guess-that-tech-47lk</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;Recently I've been having the good luck of accepting some code challenges, and have run into what feels like forgetting your dates name. &lt;/p&gt;

&lt;p&gt;I've forgotten some of the tech stacks, but do not fear, we have sites other than Stack Overflow to look to for help. Although ultimately we do end up with some cool Stack Overflow graphs at the end of my list.&lt;/p&gt;

&lt;p&gt;Basically, if you ever need help trying to understand which of your skills to polish as an interview with a company becomes more of a reality, this small list should lend you some big help.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Where
&lt;/h2&gt;

&lt;p&gt;1) &lt;a href="https://builtwith.com/"&gt;Built With&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Build lists of websites from our database of 35,270+ web technologies and over a quarter of a billion websites showing which sites use shopping carts, analytics, hosting and many more. Filter by location, traffic, vertical and more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2) &lt;a href="https://www.similartech.com/"&gt;Similar Tech&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Our proprietary technology scans more than 30 billion web pages per month. We monitor and analyze over 317 million domains to help companies get more data and make better decisions based on technology adoptions. SimilarTech was founded in 2014 as a result of a spin off of SimilarWeb, our unique data partner.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3) &lt;a href="https://whatcms.org/"&gt;What CMS&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;WhatCMS.org looks at a variety of factors to determine which CMS a website is using. First, we fetch the webpage for the url in question then begin looking for indicators in the html markup and headers. Indicators range from the very obvious &lt;code&gt;&amp;lt;meta name="generator" ...&amp;gt;&lt;/code&gt; tag or &lt;code&gt;x-powered-by&lt;/code&gt; header to less obvious directory structures, asset files, JavaScript code and more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;4) &lt;a href="https://rescan.io/?redirect_allora=1"&gt;Rescan&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We provide lists of websites using different technologies. We also run a free website analysis tool. We update our lists at 16:00 UTC time (current UTC time: 02:00). You can compare your time zone with UTC here. &lt;br&gt;
For some websites we provide emails along with the lists. We also provide Alexa rank, phones, website IP, web server type, codepage and country (if any).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;5) &lt;a href="https://insights.stackoverflow.com/trends?utm_source=so-owned&amp;amp;utm_medium=blog&amp;amp;utm_campaign=trends&amp;amp;utm_content=blog-link&amp;amp;tags="&gt;StackOverflow Trends&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See how technologies have trended over time based on use of their tags since 2008, when Stack Overflow was founded. Enter up to 15 tags to compare growth and decline.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;6) &lt;a href="https://insights.stackoverflow.com/survey/"&gt;StackOverflow Dev Survey&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With nearly 90,000 responses fielded from over 170 countries and dependent territories, our 2019 Annual Developer Survey examines all aspects of the developer experience from career satisfaction and job search to education and opinions on open source software.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/SmviFXCM3vpCM/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/SmviFXCM3vpCM/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
And so, we've come full circle 



</description>
      <category>tips</category>
      <category>devtips</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Rails File Structure Overview</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Thu, 05 Sep 2019 14:18:55 +0000</pubDate>
      <link>https://dev.to/krtb/rails-file-structure-overview-ei3</link>
      <guid>https://dev.to/krtb/rails-file-structure-overview-ei3</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;This is a quick read, more so a reference guide as to what those files in your new rails app are about&lt;/p&gt;

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

&lt;p&gt;If you're like me and just are getting to know RBENV after uninstalling rvm then you'd want to start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;rails
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then you get a long list of gems that installed successfully&lt;/p&gt;

&lt;p&gt;After which you hit your keyboard with the good ol'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;rails new cool-project
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once you navigate over to your code editor of choice you would see the following files, let's take a look at what each one does in general.&lt;/p&gt;

&lt;h2&gt;
  
  
  File Structure
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;APP

&lt;ul&gt;
&lt;li&gt;contains models, views, controllers&lt;/li&gt;
&lt;li&gt;core functions found here&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;only place&lt;/strong&gt; where you can make changes and not have to restart your rails server&lt;/li&gt;
&lt;li&gt;location of Non-Ruby files such as, but not limited to

&lt;ul&gt;
&lt;li&gt;JS, CSS, images, fonts, more assets  such as these&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;BIN

&lt;ul&gt;
&lt;li&gt;built in rails tasks. You shouldn't be worrying about this folder way too much&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;CONFIG

&lt;ul&gt;
&lt;li&gt;Settings that control behavior:&lt;/li&gt;
&lt;li&gt;Environment Settings&lt;/li&gt;
&lt;li&gt;modules that initialize when app starts&lt;/li&gt;
&lt;li&gt;app settings&lt;/li&gt;
&lt;li&gt;data base settings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;app routes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;secret key base&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;DB

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;schema.rb file&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;this lists:&lt;/li&gt;
&lt;li&gt;database tables&lt;/li&gt;
&lt;li&gt;columns&lt;/li&gt;
&lt;li&gt;column associated data types&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;seeds.rb file&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;enables you to create data to be used in the app&lt;/li&gt;
&lt;li&gt;can quickly integrate data into the app&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;LIB

&lt;ul&gt;
&lt;li&gt;houses &lt;strong&gt;custom rake tasks&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;example case: can run in the background, make calls to an external API, and sync returned data in app's db.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;LOG

&lt;ul&gt;
&lt;li&gt;application logs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DEBUGGING!&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;for a prod env, you'll probably use outside service&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;PUBLIC

&lt;ul&gt;
&lt;li&gt;Custom error pages&lt;/li&gt;
&lt;li&gt;robots.txt&lt;/li&gt;
&lt;li&gt;controls how search engines index the app&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SPEC&lt;/strong&gt;/test (will mostly use RSPEC)

&lt;ul&gt;
&lt;li&gt;test suite:&lt;/li&gt;
&lt;li&gt;specs, factories, test helpers, test configuration&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;TMP

&lt;ul&gt;
&lt;li&gt;for temporary files, never really had to deal with this&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;VENDOR

&lt;ul&gt;
&lt;li&gt;mainly used to integrate client-side MVC framworks, such as Angular&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;GEMFILE

&lt;ul&gt;
&lt;li&gt;all of your gems from your project&lt;/li&gt;
&lt;li&gt;outside libraries used in the app&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;after changing gemfile, rerun&lt;/em&gt; &lt;strong&gt;BUNDLE&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;calls in code dependencies of application&lt;/li&gt;
&lt;li&gt;(Gems are ruby files that extend functions of app)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;GEMFILE.lock

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;don't edit!&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;dependencies and associated versions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;README.rdoc

&lt;ul&gt;
&lt;li&gt;for your to document details of app&lt;/li&gt;
&lt;li&gt;instructions for other devs&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hopefully this helps you the next time your trying to remember what folder to look into to fix a bug 🐛&lt;/p&gt;

&lt;p&gt;Photo Credit:&lt;br&gt;
&lt;a href="https://unsplash.com/photos/EPppwcVTZEo"&gt;Helloquence&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>Why and How I Replaced RVM with RBENV</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Fri, 30 Aug 2019 17:14:00 +0000</pubDate>
      <link>https://dev.to/krtb/why-and-how-i-replaced-rvm-with-rbenv-23ad</link>
      <guid>https://dev.to/krtb/why-and-how-i-replaced-rvm-with-rbenv-23ad</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;My morning started out like most people's, as I sat down at my computer while eating a bacon-egg-and-cheese on an everything bagel. And then, like everyone's morning it quickly made a hard right turn in a different direction. &lt;/p&gt;

&lt;p&gt;On the lookout for an fun open-source project to contribute to, I found myself on the &lt;a href="https://github.com/thepracticaldev/dev.to"&gt;Dev.to github repo&lt;/a&gt;. When looking into their documentation, I find that they're using something called..."&lt;strong&gt;Rbenv&lt;/strong&gt;". Huh?!&lt;/p&gt;

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

&lt;p&gt;Before we shove off port and start sailing towards gem covered seas, I do want to let you, my faithful crew, know that this article is going to explain what RVM is, then Rbenv, why either matter, and the process I had to undergo to successfully transition.&lt;/p&gt;

&lt;p&gt;I've been watching too much, &lt;a href="https://www.metacritic.com/tv/the-terror"&gt;The Terror&lt;/a&gt;. The first seasons was good! The second season, not so much.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Why
&lt;/h2&gt;

&lt;p&gt;Okay, why are either of these package managers for Ruby relevant? &lt;/p&gt;

&lt;p&gt;Well, firstly, here's a quick snippet on &lt;em&gt;package-managers&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Package_manager"&gt;"A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer's operating system in a consistent manner."&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Option #1 -&amp;gt; &lt;a href="https://rvm.io/"&gt;RVM&lt;/a&gt; (&lt;em&gt;ruby version manager&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;RVM was mainly authored by &lt;strong&gt;Wayne Eseguin&lt;/strong&gt;, and you can still find him on &lt;a href="https://twitter.com/wayneeseguin"&gt;twitter&lt;/a&gt; maintaining RVM, along with other projects. Work on RVM first began in &lt;a href="https://wiki.archlinux.org/index.php?title=RVM&amp;amp;action=history"&gt;February, 2012&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;RVM had a quick installation process, and one that didn't require a lot of spelunking into your files. It's great for those starting out, simple projects and all. &lt;/p&gt;

&lt;p&gt;This isn't about one being better than the other, like any tech it's about weighing the pros and cons, aligning those with what it is that you're trying to achieve, and choosing what you want to use. Competing technologies can often co-exist and drive each other to improve in order to gain more users. RVM is great for what it is, but once you find yourself in larger companies you may start asking questions and looking into what's most efficient for your own work process. &lt;/p&gt;

&lt;p&gt;Much of the gripe with RVM has to do with the weight of it's installation process. &lt;/p&gt;

&lt;p&gt;Here's &lt;a href="https://batkin.tumblr.com/post/8847990062/on-rvms-cd-script"&gt;an extensive explanation&lt;/a&gt;, clarifying misinformation and filling in some gaps in what's said about RVM's 'cd' function.&lt;/p&gt;

&lt;p&gt;A quick summary of the issue would be that, RVM creates a new function that hacks into the &lt;em&gt;cd&lt;/em&gt; command to easily provide you with it's feature of switching Ruby versions automatically. &lt;/p&gt;

&lt;p&gt;Who loves Hacker News? Well, here's a wonderful thread after Rbenv's first release, where it seems the whole of the Ruby community finally felt it had a safe space to let out years of pent up frustrations in one cathartic thread.&lt;/p&gt;

&lt;p&gt;Here's the HackerNews post, titled:&lt;a href="https://news.ycombinator.com/item?id=2874862"&gt;"Rbenv, an unobtrusive rvm replacement"&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/14vaeCWc35rGSI/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/14vaeCWc35rGSI/giphy.gif" alt="SPILL THE TEA"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are some highlights from the thread&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"With all due respect, ruby is a language, and rvm is a collection of really fragile and dangerous shell script hacks."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And another&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"RVM is hardly development ready, imho. Every week I run into problems/confusion with the environment it creates and expects.&lt;br&gt;
I would never put it anywhere near production."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And one last one&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The complete lack of a changelog doesn't help either. I never know whether something's going to break in a new release and almost every new release has some little semantic change that borks my system."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, for good posture I'll include some of the comments that were in support of RVM, that also highlight the reason why I would believe that most coding boot camps have added it into their curriculum.&lt;/p&gt;

&lt;p&gt;Uno&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I'll take your word for it. For me, it mostly saves me a bunch of time. &lt;strong&gt;Edit:&lt;/strong&gt; Just in case I'm coming off as snarky here, I don't mean to. My projects tend to be on the simpler end, and rvm saves me a lot of time. I'm sure it's a little cowboyish for bigger projects - I was just wondering if there was something about rvm that made it universally inappropriate for production use. &lt;strong&gt;Double Edit:&lt;/strong&gt; "a bunch" is probably an overstatement. rvm was a great help transitioning to 1.9.2. I'm not sure if it will provide much utility going forward. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;...Dos&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is kind of a classic "fast, correct - choose one" debate. If saving time is more important, perhaps you should use RVM in production, if correctness is more important, you probably shouldn't. It comes down to how expensive your mistakes are. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;...Tres&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you only have one server and can script most of the install process it's not a problem. When you have more than one server, rvm is not going to save you time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/110H2727GW5ZcI/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/110H2727GW5ZcI/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
If you haven't seen 'Spin City', get to it!



&lt;p&gt;Option #2 -&amp;gt; &lt;a href="https://github.com/rbenv/rbenv"&gt;RBENV&lt;/a&gt;(&lt;em&gt;ruby environment&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;RBENV was authored by &lt;strong&gt;Sam Stephenson&lt;/strong&gt;, who can be found on &lt;a href="https://twitter.com/sstephenson"&gt;twitter&lt;/a&gt;. He's currently working at &lt;a href="https://basecamp.com/"&gt;Basecamp&lt;/a&gt;. Work on RBENV first began in &lt;a href="https://wiki.archlinux.org/index.php?title=Rbenv&amp;amp;action=history"&gt;August, 2012&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A major pull of rbenv's it that it's &lt;em&gt;lighter&lt;/em&gt;. And by that we mean that it doesn't have to throw as many hooks into your computer system. &lt;/p&gt;

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

&lt;p&gt;Here's some of the highlights from their own github repo where the development team goes into comparing the two technologies and how they compare.&lt;/p&gt;

&lt;h3&gt;
  
  
  rbenv does…
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Provide support for specifying application-specific Ruby versions.&lt;/li&gt;
&lt;li&gt;Let you change the global Ruby version on a per-user basis.&lt;/li&gt;
&lt;li&gt;Allow you to override the Ruby version with an environment variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  In contrast with RVM, rbenv does not…
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Need to be loaded into your shell. Instead, rbenv's shim approach works by adding a directory to your $PATH.&lt;/li&gt;
&lt;li&gt;Override shell commands like cd or require prompt hacks. That's dangerous and error-prone.&lt;/li&gt;
&lt;li&gt;Have a configuration file. There's nothing to configure except which version of Ruby you want to use.&lt;/li&gt;
&lt;li&gt;Install Ruby. You can build and install Ruby yourself, or use ruby-build to automate the process.&lt;/li&gt;
&lt;li&gt;Manage gemsets. Bundler is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the rbenv-gemset plugin.&lt;/li&gt;
&lt;li&gt;Require changes to Ruby libraries for compatibility. The simplicity of rbenv means as long as it's in your $PATH, nothing else needs to know about it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F"&gt;thanks rbenv!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Personally, at this point of doing my research I was pretty convinced that it was time to take an hour at most out of my day to clean &lt;em&gt;RVM&lt;/em&gt; out of my system and run through RBENV's installation process.&lt;/p&gt;

&lt;p&gt;But for the sake of education, I'll some info on the technicality behind how RBENV works.&lt;/p&gt;

&lt;p&gt;1) you run a command, be it &lt;em&gt;Ruby&lt;/em&gt; or &lt;em&gt;Rake&lt;/em&gt; &lt;br&gt;
2) your computer will then run through directories, looking for that particular executable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;/usr/local/bin:/usr/bin:/bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;3) There's an environment called &lt;strong&gt;PATH&lt;/strong&gt;&lt;br&gt;
4) this contains a list of directories that looks like the code above&lt;br&gt;
5) Every directory is separated by a color, ':'&lt;br&gt;
6) this process will occur left to right, have the object on the left take priority over whatever is left over to the right&lt;/p&gt;


&lt;center&gt;&lt;strong&gt;In walk the SHIMS&lt;/strong&gt;&lt;/center&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/xTk9ZS8Ury96MENgAg/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/xTk9ZS8Ury96MENgAg/giphy.gif" alt="THE SIMS"&gt;&lt;/a&gt;&lt;/p&gt;
no,no, no, not The Sims. The SHIMS!



&lt;p&gt;1) rbenv inserts "shims" at the front of your PATH&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;2) rbenv uses &lt;a href="https://www.quora.com/What-is-rehashing-in-a-data-structure"&gt;&lt;em&gt;rehashing&lt;/em&gt;&lt;/a&gt; to maintain your commands in that directory&lt;br&gt;
3) it them matches ruby commands across your system&lt;br&gt;
4) these commands can range from irb, gem, rake, rails, to of course, ruby &lt;/p&gt;
&lt;h2&gt;
  
  
  The Where
&lt;/h2&gt;

&lt;p&gt;The first thing you should worry about before swapping out one technology for another should be the packages that you've installed so far within that manager.&lt;/p&gt;

&lt;p&gt;If you, like me, already had RVM installed cause that's the direction your boot camp took you in and you didn't want to stir the pot on day two of a daunting 3 months ahead...&lt;/p&gt;

&lt;p&gt;Type into your terminal (&lt;em&gt;hopefully BASH&lt;/em&gt;):&lt;/p&gt;

&lt;pre&gt;
gem list --local
&lt;/pre&gt;

&lt;p&gt;Then you'd get a list of gems that were installed on your local system:&lt;/p&gt;

&lt;pre&gt;
*** LOCAL GEMS ***

actioncable (5.2.1, 5.0.7)
actionmailer (5.2.1, 5.0.7)
actionpack (5.2.1, 5.0.7)
actionview (5.2.1, 5.0.7)
active_model_serializers (0.10.7)
activejob (5.2.1, 5.0.7)
activemodel (5.2.1, 5.2.0, 5.0.7)
...
ETC!
&lt;/pre&gt;

&lt;p&gt;Then, you'd want to copy this and paste it somewhere for you to reference later on. I don't know if there's a simpler way to export and import your gems into a new package manage like Rbenv, but I don't know it and it's already 11am! No time!&lt;/p&gt;

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

&lt;p&gt;The next step would be choosing between two of the following RVM commands to remove the manager&lt;/p&gt;

&lt;p&gt;1) rvm implode&lt;/p&gt;

&lt;p&gt;2) gem uninstall rvm&lt;/p&gt;

&lt;p&gt;Additionally, if you created special script calls check these places&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;~/.bashrc&lt;/li&gt;
&lt;li&gt;~/.bash_profile&lt;/li&gt;
&lt;li&gt;~/.profile&lt;/li&gt;
&lt;li&gt;~/.zshrc&lt;/li&gt;
&lt;li&gt;~/.zlogin&lt;/li&gt;
&lt;/ul&gt;
Personally, I just open my VScode environment, from my main directory. ['. code' in the terminal]


&lt;h2&gt;
  
  
  The How
&lt;/h2&gt;

&lt;p&gt;Alright! So I went ahead and used 'rvm implode' in my terminal, honestly due to just wanting it all gone in one go and reading this was the first command I should try.&lt;/p&gt;

&lt;p&gt;I soon as I ran it though, I saw this:&lt;/p&gt;

&lt;pre&gt;
my-local-machine-location.../.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/compass-core-1.0.3/stylesheets: Permission denied
&lt;/pre&gt;

&lt;p&gt;And so, these lines keep printing out, each ending with 'permission denied'. &lt;/p&gt;

&lt;p&gt;After contol C-ing it I then got...&lt;/p&gt;

&lt;pre&gt;
Failed to completely remove /Users/kurt/.rvm -- You will have to do so manually.
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Fine. The hard way then.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Seems like when I first ran through the installation process I did it incorrectly, or at some point I moved the files.&lt;/p&gt;

&lt;p&gt;And yes, you can also try running "&lt;em&gt;rvm implode --force&lt;/em&gt;" flag. And before anyone start having a panic attack about forcing anything, it didn't work either.&lt;/p&gt;

&lt;p&gt;Back to StackOverflow...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/vL45Gljql7rTG/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/vL45Gljql7rTG/giphy.gif" alt="A FEW MOMENTS LATER SPONGEBOB"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Eureka!&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/3558656/how-can-i-remove-rvm-ruby-version-manager-from-my-system"&gt;How Can I Remove RVM ruby version manager from my system?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And so I implemented the command that was most voted, and actually originally from RVM's own troubleshooting page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://rvm.io/support/troubleshooting"&gt;How do I completely clean out all traces of RVM from my system, including for system wide installs? &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, below is the line I entered&lt;/p&gt;

&lt;pre&gt;
/usr/bin/sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm /usr/local/bin/rvm

AND

/usr/bin/sudo /usr/sbin/groupdel rvm

AND

/bin/echo

AND

rm -rf /usr/local/rvm
&lt;/pre&gt;

&lt;p&gt;When I ran my next calls, I got that no such file or directory exists.&lt;/p&gt;

&lt;pre&gt;
sudo rm /etc/profile.d/rvm.h
sudo rm /etc/rvmrc
sudo rm ~/.rvmrc
&lt;/pre&gt;

&lt;p&gt;I ran through some other removal commands to make sure that nothing remained, getting a response that RVM did not exist after each.&lt;/p&gt;

&lt;p&gt;I then went into my local files, found refrences to RVM and commented them out for now. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;~/.bashrc&lt;/li&gt;
&lt;li&gt;~/.bash_profile&lt;/li&gt;
&lt;li&gt;~/.profile&lt;/li&gt;
&lt;li&gt;~/.zshrc&lt;/li&gt;
&lt;li&gt;~/.zlogin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once I start using RBENV and make sure nothing is badly broken, I'll go back and actually delete the lines. But what I've learned from experience is never get rid of something unless you've tested and made suer you don't need it anymore. Thus why I have around 50 tabs opne...&lt;/p&gt;

&lt;p&gt;run the following command to check all of your hidden files&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; ~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/HwmDZaI4YEeZ2/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/HwmDZaI4YEeZ2/giphy.gif" alt="I TAKE NAME RIGHT HERE"&gt;&lt;/a&gt;&lt;/p&gt;
I know I know, I'm tired too



&lt;h3&gt;
  
  
  Now time to install RBENV (:
&lt;/h3&gt;

&lt;p&gt;This actually didn't take as long as expected.&lt;/p&gt;

&lt;p&gt;Gotchas to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;have &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt; installed! This post is already mad long, so you can click the link and run through that.&lt;/li&gt;
&lt;li&gt;always restart your terminal after pasting in commands into your bash files. Even if you think you don't need it, just good to give it a clean start.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Helpful Links that also do a setup walk throughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/traumverloren/fa5c30056319992c4dab"&gt;This gist from traumverloren&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://thoughtbot.com/blog/using-rbenv-to-manage-rubies-and-gems"&gt;Thoughtbot also uses rbenv&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-macos"&gt;DigitalOcean and their rbenv setup process&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1) update homebrew&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew update
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;2) then install rbenv through homebrew&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;rbenv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;3) This part was a bit weird cause I thought it wasn't working. Go to your .bash_profile/.bashrc files and add in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.rbenv/bin:&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;rbenv init -&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you're using ZSH, then just paste &lt;code&gt;eval "$(rbenv init -)"&lt;/code&gt; into your .zshrc file&lt;/p&gt;

&lt;p&gt;4) okay, here's where I borked myself. 'rbenv init' is only to print out instructions on how to integrate shell commands. Which is what we did in step 3. So when you read that, run it, and just get the same instructions, don't freak out.&lt;/p&gt;

&lt;p&gt;5) run this to check that everything installed properly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And you should see something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;Checking &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;rbenv&lt;span class="s1"&gt;' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install'&lt;/span&gt; support: /usr/local/bin/rbenv-install &lt;span class="o"&gt;(&lt;/span&gt;ruby-build 20190828&lt;span class="o"&gt;)&lt;/span&gt;
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;YAY!&lt;/p&gt;

&lt;p&gt;Okay now, let's see the ruby list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;rbenv &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Annnnd let's install the latest. Make sure to check the latest version of Ruby on their &lt;a href="https://www.ruby-lang.org/en/downloads/"&gt;site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Then simply add in the default one you'd like to be available globally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;rbenv &lt;span class="nb"&gt;install &lt;/span&gt;2.6.4 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
above ruby version as of August 2019





&lt;p&gt;Also, you're probably going to want to install the bundler to bundle and install gems&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;bundler
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;center&gt;We did it!!!&lt;/center&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1kTKRsMWY44MAlV2QW/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1kTKRsMWY44MAlV2QW/giphy.gif" alt="GET DOWN FRIDAY, TOY STORY, HARRY POTTER"&gt;&lt;/a&gt;&lt;/p&gt;
Ah yes, I can feel the joy



&lt;h2&gt;
  
  
  TLDR;
&lt;/h2&gt;

&lt;p&gt;I went through the what RVM and RBVENV were and looked at their pros and cons. It all boiled down to speed of getting things working versus quality. After which the second have of this post was dedicated to my own removal/installation steps. Hopefully this helps some people out there, I know it would have come in handy when I set out to do this. If it doesn't, there's always the internets and stackoverflow! &lt;/p&gt;

&lt;p&gt;Credits:&lt;br&gt;
&lt;a href="https://unsplash.com/@charlesdeluvio?utm_medium=referral&amp;amp;utm_campaign=photographer-credit&amp;amp;utm_content=creditBadge" rel="noopener noreferrer" title="Download free do whatever you want high-resolution photos from Charles 🇵🇭"&gt;&lt;span&gt;unsplash: &lt;/span&gt;&lt;span&gt;Charles 🇵🇭&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>bash</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Functional VS Object-Oriented Programming</title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Mon, 26 Aug 2019 19:41:28 +0000</pubDate>
      <link>https://dev.to/krtb/functional-vs-object-oriented-programming-357</link>
      <guid>https://dev.to/krtb/functional-vs-object-oriented-programming-357</guid>
      <description>&lt;h1&gt;
  
  
  The Gist
&lt;/h1&gt;

&lt;p&gt;Different programming languages have different features, or &lt;em&gt;paradigms&lt;/em&gt;, that can be used to classify them.&lt;/p&gt;

&lt;p&gt;Today we'll take a look at two of the most talked about, functional and object-oriented.&lt;/p&gt;

&lt;p&gt;Edit #1: And as &lt;a href="https://dev.to/adam_cyclones"&gt;Adam&lt;/a&gt; pointed out, the two are not pitted against each other, they're just different! These are only two of a wide array of varying approaches that could all server(typos are the best puns) you better, so never stop doing your research!&lt;/p&gt;

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

&lt;h2&gt;
  
  
  The What
&lt;/h2&gt;

&lt;p&gt;Firstly, let's take a look at some of the commonalities&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Things either approach will have to deal with

&lt;ul&gt;
&lt;li&gt;Data

&lt;ul&gt;
&lt;li&gt;what your program wants to KNOW and USE&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Behavior

&lt;ul&gt;
&lt;li&gt;what your program is looking to DO and HOW&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There's a reason why most coding boot camps start you off with ruby, or python, and that's because they're both very eye-friendly languages. Let's use Ruby for our walk through!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/85RTAcTGvcTxm/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/85RTAcTGvcTxm/giphy.gif" alt="Ruby from Steven Universe"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Object-Oriented Programming(&lt;em&gt;OOP&lt;/em&gt;)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Classes often used to generate object instances&lt;/li&gt;
&lt;li&gt;Class defines the attributes with which we want to imbue our object.&lt;/li&gt;
&lt;li&gt;We will give our class "&lt;em&gt;instance methods&lt;/em&gt;", which will exist within our object.&lt;/li&gt;
&lt;li&gt;These instance methods can be called on the object itself.&lt;/li&gt;
&lt;li&gt;"initialize", is not an instance method, but instead tells the class what attributes it will have at the moment of it's creation. &lt;/li&gt;
&lt;li&gt;Every new instance of our object will contain preset &lt;strong&gt;data&lt;/strong&gt; and &lt;strong&gt;behavior&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;As noted above, data will be provided to our instance upon creation&lt;/li&gt;
&lt;li&gt;We then use methods on our instance object to manipulate it's data&lt;/li&gt;
&lt;li&gt;All of the important information our objects contain is stored safely within their classes. If you can imagine being an engineer at a fairly large company, with a lot of pre-written code, you can also see where this would come in handy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Core Concepts&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Abstraction&lt;/li&gt;
&lt;li&gt;Inheritance&lt;/li&gt;
&lt;li&gt;Polymorphism&lt;/li&gt;
&lt;li&gt;Encapsulation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

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

&lt;pre&gt;
class Cat
  def initialize(name, mood)
    @name = name
    @mood = mood
  end

  def change_name(name)
    @name=name
  end

  def change_mood(mood)
    @mood = mood
  end
end 

kuma = Cat.new("Kuma", "mischievous")
&lt;/pre&gt;

&lt;h3&gt;
  
  
  What happened above?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We created a Cat class, or blue-print, for what we want to be able to do with our Cat instances&lt;/li&gt;
&lt;li&gt;We initialized our Cat with a &lt;em&gt;name&lt;/em&gt; and &lt;em&gt;mood&lt;/em&gt;. If you've ever hung out with cats, you'll know their mood is the second thing you remember about them after their name. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's change their name and mood!&lt;/p&gt;

&lt;pre&gt;
kuma.change_name("Grapefruit")
kuma.name
# "Grapefruit"

kuma.change_mood("post-meal-happy")
kuma.mood
# "post-meal-happy" 
&lt;/pre&gt;

&lt;h3&gt;
  
  
  What happened above?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Using the &lt;em&gt;change_name()&lt;/em&gt; method allowed us to change the name of our Cat class instance object&lt;/li&gt;
&lt;li&gt;Using the &lt;em&gt;change_mood()&lt;/em&gt; method allowed us to change the mood of our Cat class instance object&lt;/li&gt;
&lt;li&gt;Our initialize method will take the name and mood we passed to our Cat object and store that information, so that we can easily access it later on&lt;/li&gt;
&lt;li&gt;'&lt;em&gt;@&lt;/em&gt;' symbols are used for instance variables, these exist in an object(&lt;em&gt;instance&lt;/em&gt;) and is used without being passed in&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Functional Programming(&lt;em&gt;FP&lt;/em&gt;)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Uses a series of small methods that each do their own specific job.&lt;/li&gt;
&lt;li&gt;Implements &lt;em&gt;composition&lt;/em&gt; or building of large tasks with smaller ones, which is also used in OOP languages, but it's pivotal to FP ones.&lt;/li&gt;
&lt;li&gt;Objects are immutable, can't be changed after being created&lt;/li&gt;
&lt;li&gt;Best fit for data science work&lt;/li&gt;
&lt;li&gt;A function is reusable&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Core Concepts&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Higher Order Functions&lt;/li&gt;
&lt;li&gt;Pure Functions&lt;/li&gt;
&lt;li&gt;Recursion&lt;/li&gt;
&lt;li&gt;Strict &amp;amp; Non-Strict Evaluation&lt;/li&gt;
&lt;li&gt;Type Systems&lt;/li&gt;
&lt;li&gt;Referential Transparency&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/yUko4cwc6nkHu/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/yUko4cwc6nkHu/giphy.gif" alt="ants"&gt;&lt;/a&gt;&lt;/p&gt;
Here we see small functions in their natural environment



&lt;pre&gt;
def doesOneThing(number){
 return number * number
end
&lt;/pre&gt;

&lt;h3&gt;
  
  
  What happened above?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Above we have an example of a pure function&lt;/li&gt;
&lt;li&gt;The same value will always be returned, as long as the same input is given&lt;/li&gt;
&lt;li&gt;There is no other operation occurring within the function that could alter our result&lt;/li&gt;
&lt;li&gt;An instant benefit is fewer lines of code!&lt;/li&gt;
&lt;li&gt;In FP, we will be viewing every thing we do as transforming data by applying some sort of operation on it, and then returning a new data set&lt;/li&gt;
&lt;li&gt;We also often times default to using a &lt;strong&gt;map&lt;/strong&gt; method, instead of &lt;strong&gt;each&lt;/strong&gt;, which creates a new copy of the data and stores it in an array. The original array is unscathed as in FP, immutability of our data is key&lt;/li&gt;
&lt;li&gt;Immutability allows us to keep track of our data's value&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Comparison Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Topic&lt;/th&gt;
&lt;th&gt;FP&lt;/th&gt;
&lt;th&gt;OOP&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;DEFINITION&lt;/td&gt;
&lt;td&gt;emphasizes evaluation of functions&lt;/td&gt;
&lt;td&gt;based on concept of objects&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DATA&lt;/td&gt;
&lt;td&gt;immutable&lt;/td&gt;
&lt;td&gt;mutable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MODEL&lt;/td&gt;
&lt;td&gt;&lt;a href="https://en.wikipedia.org/wiki/Declarative_programming"&gt;declarative programming&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://en.wikipedia.org/wiki/Imperative_programming"&gt;imperative programming&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SUPPORT&lt;/td&gt;
&lt;td&gt;parallel programming supported&lt;/td&gt;
&lt;td&gt;No Support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EXECUTION&lt;/td&gt;
&lt;td&gt;statements can be executed in any order&lt;/td&gt;
&lt;td&gt;Need an order&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ITERATION&lt;/td&gt;
&lt;td&gt;Recursion&lt;/td&gt;
&lt;td&gt;Loops&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BASIC ELEMENTS&lt;/td&gt;
&lt;td&gt;Functions &amp;amp; Variables&lt;/td&gt;
&lt;td&gt;Objects &amp;amp; Methods&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;USES&lt;/td&gt;
&lt;td&gt;Few things with need for more operations&lt;/td&gt;
&lt;td&gt;Many things with few operations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://www.educba.com/functional-programming-vs-oop/"&gt;Thanks to EDUCBA!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But which one?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, as per this sick &lt;a href="http://stackoverflow.com/questions/2078978/ddg#2079678"&gt;stackoverflow&lt;/a&gt; post, here are some key concepts to keep in mind when considering these two very popular approaches.&lt;/p&gt;

&lt;p&gt;OOP&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Helpful when dealing with a fixed set of &lt;strong&gt;operations on things&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;As your code evolves, you &lt;em&gt;add new things&lt;/em&gt;

&lt;ul&gt;
&lt;li&gt;this means that you add new classes, which make use of existing methods&lt;/li&gt;
&lt;li&gt;existing classes are left alone&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Danger Zone&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding a new operation may require editing many class definitions to add a &lt;strong&gt;new method&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;FP&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Helpful when you have a &lt;strong&gt;fixed set of things&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;As your code evolved, you &lt;strong&gt;add new operations&lt;/strong&gt; &lt;em&gt;on&lt;/em&gt; things.

&lt;ul&gt;
&lt;li&gt;this means you add new functions which compute with &lt;em&gt;existing data types&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;existing functions are left alone&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Danger Zone&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a new thing may require editing many function definitions to add a &lt;strong&gt;new case&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  TLDR;
&lt;/h3&gt;

&lt;p&gt;Object-Oriented Programming uses Classes, objects and methods to achieve it's lofty goals. Functional Programming on the other hand makes use of an army of  pure functions and variables to to build a larger whole. Languages dedicated to on or the other each come with their own gotchas (looking at you JavaScript 😭). Make sure to research the communities supporting whatever language or framework you're looking at, and you'll be steered in the somewhat right direction. That is, until you hit a huge bug and try to turn in the other direction...this is ill advised but not impossible. Still though, like adding Redux to your React app, why would you give yourself that extra work? Plan, plan, plannnn!&lt;/p&gt;

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

</description>
      <category>learning</category>
      <category>beginners</category>
      <category>oop</category>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>Putting Asynchronous Code in a Headlock </title>
      <dc:creator>Kurt Bauer</dc:creator>
      <pubDate>Mon, 26 Aug 2019 16:07:20 +0000</pubDate>
      <link>https://dev.to/krtb/putting-asynchronous-code-in-a-headlock-3npi</link>
      <guid>https://dev.to/krtb/putting-asynchronous-code-in-a-headlock-3npi</guid>
      <description>&lt;p&gt;&lt;a href="https://i.giphy.com/media/3o6MblbJPZ4eO5FBxC/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3o6MblbJPZ4eO5FBxC/giphy.gif" alt="The Simpsons GIF"&gt;&lt;/a&gt;&lt;/p&gt;
If only we were all as enlightened as Homie



&lt;h2&gt;
  
  
  The Gist
&lt;/h2&gt;

&lt;p&gt;In my last post, I lightly went over what asynchronous functions were and how they related to AJAX, which makes use of it in the synchronous JavaScript universe.&lt;/p&gt;

&lt;p&gt;Here I'll take some time to go more in depth into async VS sync, and different patterns that are applied in order to achieve asynchronicity.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Why
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It's useful information when attempting to access databases or APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The What
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Synchronous Example
&lt;/h4&gt;

&lt;pre&gt;
// An example of an index.js file, running Node, would see this in the terminal
 
console.log('This is synchronous code, or blocking')
console.log('waiting for the first to complete before running')
&lt;/pre&gt;

&lt;h4&gt;
  
  
  Asynchronous Example
&lt;/h4&gt;

&lt;pre&gt;
// An example of an index.js file, running Node, would see this in the terminal
 
console.log('This is synchronous code, or blocking')

setTimeOut(()=&amp;gt; console.log('Waiting to run, not causing a blockage'), 2000)

console.log('waiting for the first to complete before running')
&lt;/pre&gt;

&lt;p&gt;The setTimeOut() function, would be an example of a function that is considered &lt;em&gt;"non-blocking"&lt;/em&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code presented above

&lt;ul&gt;
&lt;li&gt;in the async example, the second setTimeOut() call will only run 2 seconds after.&lt;/li&gt;
&lt;li&gt;The first and last calls would show up in your terminal, and after the allotted time, the middle function.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  What Have we learned so far?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Synchronous Code (&lt;em&gt;blocking&lt;/em&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BLOCKING - finishes work only after it completes&lt;/li&gt;
&lt;li&gt;Needs 2 or more threads or will cause program to crash/freeze &lt;/li&gt;
&lt;li&gt;Would see this occur when making calls to a database/api at an external url for example&lt;/li&gt;
&lt;li&gt;The single thread is focused on completing the first task in the call-stack that it finds, and will put the rest of the tasks in the code on hold until it finishes getting back the requested information to you&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Asynchronous Code (&lt;em&gt;non-blocking&lt;/em&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NON-BLOCKING: returns immediately, later on relays back finished work&lt;/li&gt;
&lt;li&gt;Only is dependent upon at least 1 thread, and your program will still be functioning safely&lt;/li&gt;
&lt;li&gt;Accessing something as large as an API can result in slow retrieval of the needed data. &lt;/li&gt;
&lt;li&gt;Your program is can freely run it's other tasks, and on the event loop, it will return to provide the needed info&lt;/li&gt;
&lt;li&gt;All in all, async stays out of your way, while a sync call will require all your program's attention. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The How
&lt;/h2&gt;

&lt;p&gt;Now that we have the terminology level covered, we can start making our way towards the common patterns or approaches that engineers use when dealing with making async calls in their code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What we have to keep in mind is that our functions will be attempting to return information as soon as you call them, but if we're reaching outwards and depending on an external source to respond...well we can never be sure of the time we'll be waiting. If we try to return information that we don't have, our program will show us one of those nasty &lt;em&gt;undefined&lt;/em&gt; calls. So, what are some steps that we can take to resolve this?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1) Callbacks&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a &lt;em&gt;CALLBACK&lt;/em&gt; function is called, when the result of an async operation is ready.&lt;/li&gt;
&lt;li&gt;in JS, a function is an object&lt;/li&gt;
&lt;li&gt;also in JS,  functions can take other functions as arguments, and can be returned by other functions&lt;/li&gt;
&lt;li&gt;THIS IS WHY THEY'RE CALLED HIGHER ORDER FUNCTIONS&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;"Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://eloquentjavascript.net/05_higher_order.html"&gt;Great link to Eloquent JavaScript reading on HOFs&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For callbacks, we usually pass a second param to our fist function, which will reference a nested function within our first function.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;pre&gt;


console.log('This is synchronous code, or blocking');

findSong(1, (song) =&amp;gt; {
  console.log('OUR SONG', song);
});

console.log('waiting for the first to complete before running')

function findSong(id, callback) {
   //Simulating a code delay below

    setTimeout(() =&amp;gt; {
      console.log('Searching for your song...');
      callback({ id: id, song: 'only 4 u' });
    }, 2000);

}
&lt;/pre&gt;

&lt;h3&gt;
  
  
  The Downside?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The problem, if not seen from my brief explanation above, is that there's a slipper slope in which you all of sudden find yourself inside...CALL BACK HELL.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Callback Hell explanation...

&lt;ul&gt;
&lt;li&gt;as you could see from my entangled explanation above, building out ever more complex callbacks can lead you into... well.. hell. It becomes ever more complicated not only to explain your code easily to other engineers, and in turn, also becomes harder for you to understand what it was that your code was doing in the first place. &lt;/li&gt;
&lt;li&gt;If you do happen do find yourself in this forsaken place, do remember that using helper functions, or &lt;strong&gt;Name Functions&lt;/strong&gt;, is helpful when trying to read through the code. When you integrate them into your nested callback mess, remember that it won't be called but you'll simply be passing a reference to the function that is located somewhere else in your file.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let's keep moving on till we find a solution that's at least more manageable. &lt;/p&gt;

&lt;p&gt;2) Promises&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are those?

&lt;ul&gt;
&lt;li&gt;The technical definition is that a promise, "holds the eventual result of an async operation"&lt;/li&gt;
&lt;li&gt;when an async operation completes, it will either error out or produce the value that you were trying to work with.&lt;/li&gt;
&lt;li&gt;Here, you are being "promised", that you will get the result of an async operation.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;A '&lt;em&gt;Promise Object&lt;/em&gt;' can come in 3 essential states

&lt;ul&gt;
&lt;li&gt;Pending State

&lt;ul&gt;
&lt;li&gt;kicks off async operation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Fulfilled State (resolved)

&lt;ul&gt;
&lt;li&gt;this means that the async operation completed successfully.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Rejected State (failed)

&lt;ul&gt;
&lt;li&gt;something went wrong while we were trying to execute our operation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is an example of a promise instance. It takes a function with two params, &lt;em&gt;resolve and reject&lt;/em&gt;.&lt;/p&gt;

&lt;pre&gt;
//somewhere in the code will want to consume this promise object, which will eventually hold our data that is promised to us in this async operation.
const firstPromise = new Promise((resolve, reject) =&amp;gt; {
})
&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Resolve and reject are both functions

&lt;ul&gt;
&lt;li&gt;used to send result of async operation to consumer of this promise.&lt;/li&gt;
&lt;li&gt;when passing a message inside of the &lt;em&gt;reject&lt;/em&gt; function, it's best practice to pass an error object
&lt;pre&gt;
reject(new Error('You've been rejected!'))
&lt;/pre&gt; &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;.catch / .then methods&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;.then &lt;/li&gt;
&lt;li&gt;good for continuing to do more work with your data that's been returned.
&lt;pre&gt;
.then(result =&amp;gt; console.log(result))
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;.catch&lt;/li&gt;
&lt;li&gt;important to use to grab any errors that may occur&lt;/li&gt;
&lt;li&gt;when you create &lt;em&gt;Error instances&lt;/em&gt;, they have message properties you can use to view the warning that you &lt;em&gt;may&lt;/em&gt; have included for yourself.
&lt;pre&gt;
.catch(err =&amp;gt; console.log('You hit an error!',err.message))
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key take away from the above explanation, is that anywhere you find a callback, in &lt;em&gt;most cases&lt;/em&gt;, you should modify that function to return a promise.&lt;/p&gt;

&lt;h3&gt;
  
  
  Consuming Prompises
&lt;/h3&gt;

&lt;p&gt;Promises are the &lt;em&gt;consumed&lt;/em&gt; by chaining &lt;em&gt;.then&lt;/em&gt; methods and traversing nested data until we get to the core of the information we were trying to obtain. We can create promise functions that each do one task, and are more easy to alter and read.&lt;/p&gt;

&lt;h3&gt;
  
  
  Settled Promises
&lt;/h3&gt;

&lt;p&gt;If working with unit testing, you can easily work with a promise that is resolved by using a promise method.&lt;/p&gt;

&lt;pre&gt;
const completed = Promise.resolve()
completed.then(result =&amp;gt; console.log(result))
&lt;/pre&gt;

&lt;p&gt;You can also test with errors&lt;/p&gt;

&lt;pre&gt;
const failed = Promise.reject(new Error('your reason'))
// it is best practice to console log only the message property, instead of the entire error object
failed.catch(error =&amp;gt; console.log(error.message))
&lt;/pre&gt;

&lt;h3&gt;
  
  
  Running them in parallel
&lt;/h3&gt;

&lt;pre&gt;
 const promiseOne = new Promise((resolve) =&amp;gt; {
 
  setTimeOut(()=&amp;gt;{
   console.log('completed!')
   resolve(1)
}, 2000)

})

 const promiseTwo = new Promise((resolve) =&amp;gt; {
 
  setTimeOut(()=&amp;gt;{
   console.log('completed!')
   resolve(1)
}, 2000)

})

//all method will return a new promise once all promises in this array are resolved
Promise.all([promiseOne, promiseTwo]).then(result =&amp;gt; console.log(result))
&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Promise.all

&lt;ul&gt;
&lt;li&gt;still only a single thread kicking off multiple operations&lt;/li&gt;
&lt;li&gt;result will be available as an array&lt;/li&gt;
&lt;li&gt;What if one of these promises fails?&lt;/li&gt;
&lt;li&gt;if any of our promises are rejected, our result will be failed, even if there are promises which were fulfilled &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Promise.race

&lt;ul&gt;
&lt;li&gt;used if you want &lt;em&gt;don't want to wait&lt;/em&gt; for all promises to complete&lt;/li&gt;
&lt;li&gt;result will not be an array, but value of first fulfilled promise&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3) Async and Await &lt;/p&gt;

&lt;pre&gt;
async function doSomethingCool(){

const artist = await findArtist(1)  //await keyword released thread to do other work
const album = await findAlbums(artist.albumName)
const song = await findSong(album[0])

console.log(song)
}

doSomethingCool() 
// returns a promise that once fulfilled doesn't result in a value.
&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Async and Await

&lt;ul&gt;
&lt;li&gt;built on top of promises&lt;/li&gt;
&lt;li&gt;syntactical sugar&lt;/li&gt;
&lt;li&gt;our code may look  synchronous, but will look something like chained promises, using .then()&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;
findArtist(1)
.then(artist =&amp;gt; getAlbums(albums.artistName))
.then(album =&amp;gt; findSong(album[0]))
.then(songs =&amp;gt; console.log('songs', songs))
.catch(err =&amp;gt; console.log('Error', err.message))
&lt;/pre&gt;

&lt;h3&gt;
  
  
  Try-Catch Block
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In order to catch our error, would have to wrap our code&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;
async function doSomethingCool(){

try {

const artist = await findArtist(1)  //await keyword released thread to do other work
const album = await findAlbums(artist.albumName)
const song = await findSong(album[0])

console.log(song)
} catch (err) {
  console.log('Error'), err.message
}


}

doSomethingCool() 

&lt;/pre&gt;

&lt;h1&gt;
  
  
  TLDR;
&lt;/h1&gt;

&lt;p&gt;Using promises, or async/await to be more abstract, allows our code to keep moving forward and frees up our single thread to take on other tasks. Then once our promise has been resolved, we can use that information with a .then() method to traverse the data or a .catch() method to take a look at how we can approach our bug with a steady head on our shoulders. And although callback/higher-order functions have their benefits, it's best to avoid plummeting into &lt;em&gt;'callback hell'&lt;/em&gt;. Good luck!&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>react</category>
      <category>node</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
