<?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: Software Development Academy</title>
    <description>The latest articles on DEV Community by Software Development Academy (@softwaredevacademy).</description>
    <link>https://dev.to/softwaredevacademy</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%2F609139%2Fe7a05548-fd92-471d-b4ae-f8267940341f.png</url>
      <title>DEV Community: Software Development Academy</title>
      <link>https://dev.to/softwaredevacademy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/softwaredevacademy"/>
    <language>en</language>
    <item>
      <title>Handling multiple pages with the external component React Router DOM</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:25:07 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/handling-multiple-pages-with-the-external-component-react-router-dom-l4a</link>
      <guid>https://dev.to/softwaredevacademy/handling-multiple-pages-with-the-external-component-react-router-dom-l4a</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/yQf1KbGiwiI"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;em&gt;Video tutorial for this article&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;React Router DOM is an external component that allows you to build bigger projects by separating your project into different pages.&lt;/p&gt;


&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=xfGciVdbktI"&gt;What is a Single Page Application&lt;/a&gt; (SPA): An excellent short video explaining what a single page application is and why they are so important.&lt;/p&gt;


&lt;h1&gt;
  
  
  Quick disclaimer
&lt;/h1&gt;

&lt;p&gt;After watching the SPA video above, we can expand about this world of SPA's using React and React Router DOM (I will refer to it as Router from now on to keep it short).&lt;/p&gt;

&lt;p&gt;The Router simulates multiple pages with a little trick of changing the browser URL using JavaScript. It is like typing &lt;code&gt;google.com&lt;/code&gt; and then &lt;code&gt;google.com/search&lt;/code&gt; but without pressing the enter key to change the page. This allows the Router to tell React it has to render different content based on the URL.&lt;/p&gt;

&lt;p&gt;The router can utilize this trick to pass information as well. For example, adding an "&lt;code&gt;?&lt;/code&gt;" at the end of the URL like &lt;code&gt;google.com/search/?cats&lt;/code&gt; or &lt;code&gt;google.com/search/?dogs&lt;/code&gt; will allow the Router to use that keyword as a variable and send it across pages.&lt;/p&gt;


&lt;h1&gt;
  
  
  Intended result
&lt;/h1&gt;

&lt;p&gt;We will have by the end of the article: &lt;a href="https://fe-react-router-dom.web.app"&gt;React Router DOM interactive example&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fVg1COBH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qrk7ygtn7jiywwryi2sv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fVg1COBH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qrk7ygtn7jiywwryi2sv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: Collage of the pages we intend to replicate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ETbA6vHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2poj5kbtx5ehydu00ke.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ETbA6vHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2poj5kbtx5ehydu00ke.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: The app hierarchy diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z8WH-zI6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4dl2uc8hchtkx621yt1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z8WH-zI6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4dl2uc8hchtkx621yt1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 3: React Router DOM most-used components.&lt;/p&gt;
&lt;h3&gt;
  
  
  Legend:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🟦 &lt;strong&gt;Blue&lt;/strong&gt;: Component created by us.&lt;/li&gt;
&lt;li&gt;🟥 &lt;strong&gt;Red&lt;/strong&gt;: Browser Router external component.&lt;/li&gt;
&lt;li&gt;🟩 &lt;strong&gt;Green&lt;/strong&gt;: Switch external component.&lt;/li&gt;
&lt;li&gt;🟪 &lt;strong&gt;Purple&lt;/strong&gt;: Route external component.&lt;/li&gt;
&lt;li&gt;🟨 &lt;strong&gt;Yellow&lt;/strong&gt;: Link external component.&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;Just by looking at the diagram, you can see how big this article will be. Now it should start making sense why it is best to teach certain React concepts in a different order.&lt;/p&gt;

&lt;p&gt;To tackle this project we will focus on 3 areas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How to install the Router&lt;/li&gt;
&lt;li&gt;How to set up the App component&lt;/li&gt;
&lt;li&gt;How to set up the Header component&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-install"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How to install the Router:
&lt;/h3&gt;

&lt;p&gt;First, we need to install the external component using NPM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save react-router-dom 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;span id="guide-app"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  App component:
&lt;/h3&gt;

&lt;p&gt;Then we proceed to import and utilize the Router components, similar to what we did in the previous article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;HeaderBar&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;./components/HeaderBar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PageA&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;./components/PageA&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PageB&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;./components/PageB&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PageC&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;./components/PageC&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;HeaderBar&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;PageA&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;PageB&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page-b"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;PageC&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page-c"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break the new code into detail:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We import not 1 but 3 components from &lt;code&gt;react-router-dom&lt;/code&gt;: &lt;code&gt;BrowserRouter&lt;/code&gt;, &lt;code&gt;Switch&lt;/code&gt;, and &lt;code&gt;Route&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt; wraps around everything. This is because anything inside it will have access to the web browser URL as a state variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Switch&amp;gt;&lt;/code&gt; is the area where you want your navigable components to appear.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; is the component that holds our individual pages. It has 2 important properties:

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;component&lt;/code&gt;: Receives the component you want to use as a page.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;path&lt;/code&gt;: The browser's route that will allow users to navigate directly to this page.&lt;/li&gt;
&lt;/ol&gt;


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

&lt;p&gt;&lt;strong&gt;Note 1:&lt;/strong&gt; Watch out the moment you do the import. React has a library called &lt;code&gt;react-dom&lt;/code&gt; (without the word router). React uses this library to navigate between components inside other components. Choosing the wrong import library will lead to errors with messages that make no sense.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note 2:&lt;/strong&gt; The header bar is outside of the &lt;code&gt;Switch&lt;/code&gt; because we do not want it to change when we navigate between pages. However, it is inside the &lt;code&gt;BrowserRouter&lt;/code&gt; because it has links that need to interact with the web browser URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note 3:&lt;/strong&gt; The first route is &lt;code&gt;/&lt;/code&gt; to represent the home page, and this route needs the word &lt;code&gt;exact&lt;/code&gt; to inform the Router to not confuse it with other routes starting with &lt;code&gt;/&lt;/code&gt; but with more words after it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RjbwlXEy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9kscca2q1oo18rx9w7j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RjbwlXEy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9kscca2q1oo18rx9w7j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span id="guide-header"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Header Bar component:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--11NTJXbH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofqe2infnmahvvqqibsw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--11NTJXbH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofqe2infnmahvvqqibsw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 4: The header bar component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;HeaderBar&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"header"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Page A&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page-b"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Page B&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page-c"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Page C&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets analyze the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We import &lt;code&gt;Link&lt;/code&gt; from &lt;code&gt;react-router-dom&lt;/code&gt;, just like we did on App.jsx with the other Router components.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; behaves like an anchor or button tag. It has the property called &lt;code&gt;to&lt;/code&gt;, where you need to write the same route you put in the &lt;code&gt;&amp;lt;Route path="" /&amp;gt;&lt;/code&gt; property.&lt;/li&gt;
&lt;/ol&gt;




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

&lt;p&gt;This covers the basics of Router navigation. In class, we will cover more complex cases like using the URL to pass variables between pages.&lt;/p&gt;

&lt;p&gt;For now, we can move to the next article: &lt;a href="https://dev.to/softwaredevacademy/manage-server-state-with-useeffect-hook-3hbc"&gt;Manage server state with useEffect hook&lt;/a&gt; to learn how to fetch data in React.&lt;/p&gt;




&lt;h1&gt;
  
  
  Additional reading:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=Law7wfdg_ls"&gt;React Router Tutorial&lt;/a&gt;: A 30 min video that explains everything you need to know about this external component. It may be long, but it explains the advanced cases like sending variables through the URL.&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;p&gt;Cover: Photo by &lt;a href="https://unsplash.com/@heidifin?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Heidi Fin&lt;/a&gt; on &lt;a href="/collections/86774607/now-what?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Form events in React</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:23:46 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/form-events-in-react-4k8a</link>
      <guid>https://dev.to/softwaredevacademy/form-events-in-react-4k8a</guid>
      <description>&lt;p&gt;This article will combine the state to manipulate formularies.&lt;/p&gt;




&lt;h1&gt;
  
  
  Intended result
&lt;/h1&gt;

&lt;p&gt;This is what we will have by the end of the article.&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%2Fuploads%2Farticles%2F1nnuqq0rx7bmzdd18pjn.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%2Fuploads%2Farticles%2F1nnuqq0rx7bmzdd18pjn.png" alt="Alt Text"&gt;&lt;/a&gt; Figure 1: A quick and simple form made in React.&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%2Fuploads%2Farticles%2F43zhgmw2sg9qi93w5hra.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%2Fuploads%2Farticles%2F43zhgmw2sg9qi93w5hra.png" alt="Alt Text"&gt;&lt;/a&gt; Figure 2: Hierarchy chart of the app. Note the boxes with dotted lines aren't components but tags inside the App.jsx&lt;/p&gt;




&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;Our code examples are getting more complex, but we can still break this down by focusing only on new things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The form tag&lt;/li&gt;
&lt;li&gt;
The input tag
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setName&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;function&lt;/span&gt; &lt;span class="nf"&gt;onSuscribe&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;event&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="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Welcome on board &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;function&lt;/span&gt; &lt;span class="nf"&gt;onName&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="nf"&gt;setName&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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Our new customer is &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onSuscribe&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onName&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="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;br&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Suscribe&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;span id="guide-form"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Form tag:
&lt;/h3&gt;

&lt;p&gt;Note that the code to trigger the submission is attached to the form instead of the button.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;onSubmit&lt;/code&gt; property in the form tag to run a function when the user press the form button.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;event.preventDefault()&lt;/code&gt; on the &lt;code&gt;onSuscribe&lt;/code&gt; function. This line is necessary to avoid the webpage to reload automatically after sending the form.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Reloading the page was the normal behavior when you needed server-sided languages to do basic form manipulation before JavaScript became a powerful language.&lt;/p&gt;

&lt;p&gt;Because the form is not directly connected to a state that changes the event, you can omit the arrow function to pass the event like in the input field.&lt;/p&gt;

&lt;p&gt;&lt;span id="guide-input"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Input tag:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The input has a property &lt;code&gt;value&lt;/code&gt; that receives the state.&lt;/li&gt;
&lt;li&gt;The input also has a property &lt;code&gt;onChange&lt;/code&gt; that runs an arrow function each time the user types inside the field.&lt;/li&gt;
&lt;li&gt;The arrow function has 2 &lt;code&gt;events&lt;/code&gt;:

&lt;ol&gt;
&lt;li&gt;The input event fired each time the user types.&lt;/li&gt;
&lt;li&gt;The same event passed as an argument to be used in a function.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;




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

&lt;p&gt;Now we are halfway done in React. The next day, we will start building large-scale applications by fetching data from a server and handling multiple pages inside our React project.&lt;/p&gt;

&lt;p&gt;You can take a break before moving to the articles intended for the next day, or &lt;a href="https://dev.to/softwaredevacademy/install-external-components-using-npm-3480"&gt;click here&lt;/a&gt; to continue your studies.&lt;/p&gt;

&lt;p&gt;If you want to see the finished code, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles" rel="noopener noreferrer"&gt;link&lt;/a&gt; and open the branch forms.&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits:
&lt;/h1&gt;

&lt;p&gt;Cover: Photo by &lt;a href="https://unsplash.com/@kellysikkema?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Kelly Sikkema&lt;/a&gt; on &lt;a href="/s/photos/forms?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Button events in React</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:22:30 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/button-events-in-react-5cml</link>
      <guid>https://dev.to/softwaredevacademy/button-events-in-react-5cml</guid>
      <description>&lt;p&gt;Behind the scenes, buttons in React behave like pure JavaScript buttons. The advantage is that you can put the event directly in the button without creating a variable to reference the button.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.youtube.com/watch?v=h33Srr5J9nY" rel="noopener noreferrer"&gt;Arrow functions&lt;/a&gt;:&lt;/strong&gt; A video that will help you convert normal functions to arrow functions to be comfortable reading React code.&lt;/p&gt;




&lt;h1&gt;
  
  
  Intended result
&lt;/h1&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%2Fuploads%2Farticles%2Fh5zid09b3076vze52rk1.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%2Fuploads%2Farticles%2Fh5zid09b3076vze52rk1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: A simple page with 2 buttons.&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%2Fuploads%2Farticles%2Flw3tutjvi8mgg2ntu14j.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%2Fuploads%2Farticles%2Flw3tutjvi8mgg2ntu14j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: App hierarchy diagram.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Legend:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;🟦 &lt;strong&gt;Blue:&lt;/strong&gt; Component created by us.&lt;/li&gt;
&lt;li&gt;◻️ &lt;strong&gt;Grey:&lt;/strong&gt; Normal tags.&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;There are many ways to create button events in React, but let's focus on 2. They depend if you want to call a function without passing arguments or if you need to pass arguments.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Calling a function without passing arguments&lt;/li&gt;
&lt;li&gt;Calling a function that needs to pass arguments&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-no"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Calling a function without passing arguments:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You click me&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's analyze the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;function myFunction() {}&lt;/code&gt; Is the function called when you click on a button.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;onClick={myFunction}&lt;/code&gt; the &lt;code&gt;onClick&lt;/code&gt; property will fire the function that you pass to it. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We don't put parenthesis in the function inside onClick. Doing so will run the function when the page load, and then the button won't work when the user clicks on it.&lt;/p&gt;

&lt;p&gt;&lt;span id="guide-yes"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Calling a function that needs to pass arguments:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;myGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's analyze the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;function myGreet(name){}&lt;/code&gt; The function to run, note that it has an argument.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;onClick={() =&amp;gt; myGreet("Eduardo")}&lt;/code&gt; In order to pass a function with arguments, we need to create a function on the fly, inside the onClick event. When the user clicks on the button, it will call the arrow function, thus, running any code inside it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is where the arrow function comes to fruition. This allows us to write a shorter syntax to avoid making our JSX messy.&lt;/p&gt;

&lt;p&gt;Finally, you can pass as many arguments as you want. But to be organized, stick to 1 or 2 arguments. If you need to pass more arguments, use an object or array for better organization.&lt;/p&gt;




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

&lt;p&gt;This article will allow you to practice how to use buttons to modify information on the screen by manipulating the state. &lt;/p&gt;

&lt;p&gt;The next article is &lt;a href="https://dev.to/softwaredevacademy/form-events-in-react-4k8a"&gt;Form events in React&lt;/a&gt; that goes deeper into the state, so users can submit data to your application.&lt;/p&gt;

&lt;p&gt;In you want to see the finished code open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles" rel="noopener noreferrer"&gt;link&lt;/a&gt; and open the branch buttons.&lt;/p&gt;




&lt;h1&gt;
  
  
  Additional reading
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/docs/handling-events.html" rel="noopener noreferrer"&gt;Handling Events&lt;/a&gt; official React documentation&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits:
&lt;/h1&gt;

&lt;p&gt;Cover photo: &lt;span&gt;Photo by &lt;a href="https://unsplash.com/@matthew_t_rader?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Matthew T Rader&lt;/a&gt; on &lt;a href="https://unsplash.com/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Manage global state with Recoil.js</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:21:01 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/manage-global-state-with-recoil-js-1h6k</link>
      <guid>https://dev.to/softwaredevacademy/manage-global-state-with-recoil-js-1h6k</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/hEJdVUwAHPQ"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;em&gt;Video tutorial of this article&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So far, we have built small projects. In the prop article, we learn how to pass information from a parent to a child. But what happens if we need to pass information between siblings. You can create the state on the parent and then send it to each child, but at one point, your main component will be full of states that should belong somewhere else.&lt;/p&gt;

&lt;p&gt;Enter global state management, a way to create state variables in a separate file that any component can import without receiving data using props.&lt;/p&gt;

&lt;p&gt;In this article, we will use &lt;a href="https://recoiljs.org" rel="noopener noreferrer"&gt;Recoil.js&lt;/a&gt;, a library created by one Facebook developer working in the React team that is the easiest way to implement global state management.&lt;/p&gt;


&lt;h1&gt;
  
  
  Intended result
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://fe-react-router-dom.web.app" rel="noopener noreferrer"&gt;Interactive demo&lt;/a&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%2Fuploads%2Farticles%2Fet3fzhmxslyev66fpzt9.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%2Fuploads%2Farticles%2Fet3fzhmxslyev66fpzt9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: Application to do. &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%2Fuploads%2Farticles%2Fztiir7n6fjl7d4k49782.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%2Fuploads%2Farticles%2Fztiir7n6fjl7d4k49782.png" alt="Alt Text"&gt;&lt;/a&gt; &lt;br&gt;
Figure 2: App hierarchy chart. Click the image to zoom it to read the description of each component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The global state is floating around to denote its independence to the component diagram.&lt;/li&gt;
&lt;li&gt;The state file extensions are &lt;code&gt;.js&lt;/code&gt; because they are plain JavaScript files instead of React components.&lt;/li&gt;
&lt;li&gt;We could have a single JavaScript file for both global state variables, but I want to teach how to import and export variables in different files.&lt;/li&gt;
&lt;li&gt;Each Recoil variable must have its own unique name, even if you have the variables in different files.&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;To work with Recoil, we need to do these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Recoil&lt;/li&gt;
&lt;li&gt;Setup App.jsx&lt;/li&gt;
&lt;li&gt;Export State Variables&lt;/li&gt;
&lt;li&gt;Import State Variables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-install"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Install Recoil
&lt;/h3&gt;

&lt;p&gt;First, we need to install Recoil using NPM inside your project folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install recoil
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;span id="guide-setup"&gt; &lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Set up App.jsx
&lt;/h3&gt;

&lt;p&gt;This step needs to be done in the &lt;code&gt;App.jsx&lt;/code&gt; regardless of where we need to use global state data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// App.jsx&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;RecoilRoot&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;recoil&lt;/span&gt;&lt;span class="dl"&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="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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RecoilRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Pet shop&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;RecoilRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;import { RecoilRoot } from "recoil"&lt;/code&gt; to enable the Recoil library&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;RecoilRoot&amp;gt;&lt;/code&gt; needs to wrap around any parent or child component that may need access to the global state.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-export"&gt; &lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Export state variables
&lt;/h3&gt;

&lt;p&gt;I'm showing one 1 state file, but this applies to any other state file as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// state/userData.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;atom&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;recoil&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;petState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;petState&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No pet choosen&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;ol&gt;
&lt;li&gt;
&lt;code&gt;import { atom } from "recoil"&lt;/code&gt;: A Recoil atom is a JavaScript &lt;a href="https://www.w3schools.com/js/js_objects.asp" rel="noopener noreferrer"&gt;Object&lt;/a&gt; used to hold the data you want as a global state variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;export const petState&lt;/code&gt; To indicate that we will import this variable into other files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;atom({})&lt;/code&gt; The object that set up this global state variable. Its parameters are:

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;key&lt;/code&gt;: The unique id of this state. To avoid confusion, use the same name as the constant.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;default&lt;/code&gt;: The initial value of this state. It can be a string, boolean, array, object, etc.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-import"&gt; &lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Import state variables
&lt;/h3&gt;

&lt;p&gt;I'm showing the Content component, but this applies to the App, Header, and Footer components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// components/Content.jsx&lt;/span&gt;

&lt;span class="c1"&gt;// Core&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useRecoilState&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;recoil&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Internal&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;countState&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;../state/siteSettings&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;petState&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;../state/userData&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;HeaderBar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Global state&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;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRecoilState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countState&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;pet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPet&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRecoilState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;petState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Method&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;onClear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setPet&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="nf"&gt;setCount&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="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"header"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"pet-choosen"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pet&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClear&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Clear choice&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This one is longer but lets take our time to analyze it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;import { useRecoilState } from "recoil"&lt;/code&gt; Instead of using React useState to handle a local state, we use Recoil to handle a global state.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;import { petState } from "../state/userData"&lt;/code&gt; Here we import the variable we created in the State file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useRecoilState(petState);&lt;/code&gt; instead of using &lt;code&gt;useState&lt;/code&gt; we use &lt;code&gt;useRecoilState&lt;/code&gt;. &lt;code&gt;petState&lt;/code&gt; is the initial value that we imported in the previous step.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can see that inside the JSX and the function that controls the button, the code is the same as using the useState hook.&lt;/p&gt;




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

&lt;p&gt;Recoil has a key advantage over other global state management libraries: It looks and behaves exactly like React hooks. Thus, making it easy to mix them without needing to learn that much.&lt;/p&gt;

&lt;p&gt;If you want to see the finished code, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles" rel="noopener noreferrer"&gt;link&lt;/a&gt; and open the branch global-state.&lt;/p&gt;




&lt;h1&gt;
  
  
  Additional reading
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://recoiljs.org/docs/introduction/installation" rel="noopener noreferrer"&gt;Recoil documentation&lt;/a&gt;: To learn more tricks that Recoil can do.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/context.html" rel="noopener noreferrer"&gt;Context API&lt;/a&gt;: The current way to do global state management on React. Is not hard to learn, but it does not organize your code as elegantly as Recoil. &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://redux.js.org" rel="noopener noreferrer"&gt;Redux&lt;/a&gt;: The original way to handle global state on React. Please do not click on it unless you want to have nightmares. It is the equivalent of the SE module (SDA students understand this inside joke) but on code.&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%2Fuploads%2Farticles%2Fkljeyn6gnrg9q0pijqyd.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%2Fuploads%2Farticles%2Fkljeyn6gnrg9q0pijqyd.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Combining Recoil with React Router DOM
&lt;/h1&gt;

&lt;p&gt;If you have &lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt; to handle navigation, it does not matter if Recoil wraps BrowserRouter or the other way around.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Valid&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RecoilRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Page&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;RecoilRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Also valid&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RecoilRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Page&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;RecoilRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fuploads%2Farticles%2F51fj5ocgrucjjqv5tu5i.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%2Fuploads%2Farticles%2F51fj5ocgrucjjqv5tu5i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Cover picture: Photo by &lt;a href="https://unsplash.com/@echaparro?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Edgar Chaparro&lt;/a&gt; on &lt;a href="/s/photos/globe?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Video tutorial: &lt;a href="https://www.youtube.com/watch?v=hEJdVUwAHPQ" rel="noopener noreferrer"&gt;RecoilJS - State Management Library For React&lt;/a&gt; by &lt;a href="https://www.youtube.com/channel/UC5hby9iDkwOTQM7PIjyjbgw" rel="noopener noreferrer"&gt;
Maksim Ivanov&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Manage server state with useEffect hook</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:18:49 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/manage-server-state-with-useeffect-hook-3hbc</link>
      <guid>https://dev.to/softwaredevacademy/manage-server-state-with-useeffect-hook-3hbc</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0ZJgIjIuY7U"&gt;
&lt;/iframe&gt;
 &lt;em&gt;Video tutorial of this article&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This article will teach the basics of the &lt;code&gt;useEffect()&lt;/code&gt; hook to make fetch calls to a server.&lt;/p&gt;

&lt;p&gt;We will use the fantastic and free API mockup resource called &lt;a href="https://jsonplaceholder.typicode.com" rel="noopener noreferrer"&gt;JsonPlaceholder&lt;/a&gt; to practice some network calls.&lt;/p&gt;

&lt;h2&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%2Fuploads%2Farticles%2Fleh6kt6dk45e3jkllmd4.png" alt="Alt Text"&gt;
&lt;/h2&gt;

&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=RvYYCGs45L4" rel="noopener noreferrer"&gt;Promises&lt;/a&gt;: Explains a way to run code &lt;strong&gt;only&lt;/strong&gt; after other code that we don't know when is going to be ready.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you want to use Async &amp;amp; Await, there is a special hook called useCallback, more info in the section: Additional reading.&lt;/p&gt;




&lt;h1&gt;
  
  
  Intended result
&lt;/h1&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%2Fuploads%2Farticles%2Ff66iflyzdwluwxnk363j.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%2Fuploads%2Farticles%2Ff66iflyzdwluwxnk363j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: Todo list&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vndc4m6liktn5sebey2.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%2Fuploads%2Farticles%2F7vndc4m6liktn5sebey2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: App hierarchy chart.&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%2Fuploads%2Farticles%2Fbz1jhkc0qj84uzt37rl6.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%2Fuploads%2Farticles%2Fbz1jhkc0qj84uzt37rl6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Anatomy of the useEffect hook
&lt;/h1&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%2Fuploads%2Farticles%2Ftkx5n1ujhnqfzju769re.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%2Fuploads%2Farticles%2Ftkx5n1ujhnqfzju769re.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 3: The parameters of the useEffect hook.&lt;/p&gt;

&lt;p&gt;The first parameter is a function usually written as an arrow function. Inside the function, you do your network call using  &lt;code&gt;fetch()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The second parameter is an array of state variables. It is used to tell React to re-render the page only when these state variable changes.&lt;/p&gt;

&lt;p&gt;If you omit the second parameter, React will enter an infinite loop, crashing the application. Why? Because as we mentioned during the &lt;a href="https://dev.to/softwaredevacademy/introduction-to-state-management-and-react-hooks-285j"&gt;Introduction to State management&lt;/a&gt;, React refreshes the page each time the state changes. But if we refresh the page, the fetch data will be called again, changing the state, and the page will be refreshed and so on a so forth.&lt;/p&gt;

&lt;p&gt;Think about the second parameter as a &lt;strong&gt;brake&lt;/strong&gt; to tell React to refresh the page once instead of entering an infinite loop.&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%2Fuploads%2Farticles%2Fi6e8k9h62k09cxcvj5jj.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%2Fuploads%2Farticles%2Fi6e8k9h62k09cxcvj5jj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;To tackle the complexity we will focus on 3 areas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;General app setup&lt;/li&gt;
&lt;li&gt;
useEffect first argument (function)&lt;/li&gt;
&lt;li&gt;
useEffect second argument (array)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;TaskItem&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;./components/Item&lt;/span&gt;&lt;span class="dl"&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="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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1 App.jsx created&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// State&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;taskData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTaskData&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="c1"&gt;// Method&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2 App.jsx useEffect()&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://jsonplaceholder.typicode.com/todos/&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;json&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;setTaskData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&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;setTaskData&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="c1"&gt;// Component&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TaskList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;taskData&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;item&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;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TaskItem&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;TaskList&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This is the first exercise we have a &lt;code&gt;console.log()&lt;/code&gt; inside the code. This is on purpose, so you can open the console and see the exact moment the &lt;code&gt;App.jsx&lt;/code&gt; component is destroyed and recreated once we have the server's data.&lt;/p&gt;

&lt;p&gt;Lets break down the code line by line:&lt;/p&gt;

&lt;p&gt;&lt;span id="guide-app"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  General App:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;We import the new hook &lt;code&gt;useEffect&lt;/code&gt; in addition to the &lt;code&gt;useState&lt;/code&gt; hook.&lt;/li&gt;
&lt;li&gt;We create a state variable called &lt;code&gt;taskItemData&lt;/code&gt; as an empty array to hold the todo items fetched from the server.&lt;/li&gt;
&lt;li&gt;We use the &lt;code&gt;useEffect()&lt;/code&gt; hook directly without assigning a const or a function.&lt;/li&gt;
&lt;li&gt;Finally, TaskList is a list of &lt;code&gt;&amp;lt;TaskItems/&amp;gt;&lt;/code&gt; by using the &lt;code&gt;taskData&lt;/code&gt; state getter, and we pass to each copy its corresponding item.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-first"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  useEffect first argument:
&lt;/h3&gt;

&lt;p&gt;Inside &lt;code&gt;useEffect&lt;/code&gt;, we pass the arrow function. This will be called each time the contents of the App component change. In this case, we want to refresh the page when new data arrives from the server.&lt;/p&gt;

&lt;p&gt;Inside the arrow function, a &lt;code&gt;fetch()&lt;/code&gt; function calls the server. Note that we need to append 2 &lt;code&gt;then()&lt;/code&gt; statements to: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To convert our raw data into legible JSON.&lt;/li&gt;
&lt;li&gt;To assign this JSON to our &lt;code&gt;taskData&lt;/code&gt; state using the &lt;code&gt;setTaskData()&lt;/code&gt; setter.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-second"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  useEffect second argument:
&lt;/h3&gt;

&lt;p&gt;We put &lt;code&gt;setTaskData&lt;/code&gt; in the array inside the second argument of the &lt;code&gt;useEffect&lt;/code&gt; hook. Because we are only calling the setter and not the getter, we don't need to add &lt;code&gt;taskData.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you omit the &lt;code&gt;[]&lt;/code&gt; entirely, React will enter an infinite loop because each time you set &lt;code&gt;setTaskData,&lt;/code&gt; the state will change, refresh the page, and when you set the data again, it will refresh over and over.&lt;/p&gt;

&lt;p&gt;If you put the &lt;code&gt;[]&lt;/code&gt; but leave it empty, React will refresh the page 1 time only. This will work for this small example, but on bigger projects, this will stop calling other network calls because you aren't allowing the page to refresh when other pieces of state change. So get used to putting the necessary state getters and setters.&lt;/p&gt;




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

&lt;p&gt;This example taught you the basics of fetching data using the useEffect hook.&lt;/p&gt;

&lt;p&gt;You can take a break before moving to the articles intended for the next day, or &lt;a href="https://dev.to/softwaredevacademy/manage-global-state-with-recoil-js-1h6k"&gt;click here&lt;/a&gt; to continue your studies.&lt;/p&gt;

&lt;p&gt;My recommendation is to practice creating individual projects for each API endpoint that &lt;a href="https://jsonplaceholder.typicode.com" rel="noopener noreferrer"&gt;JSONPlaceholder&lt;/a&gt; has. The goal is to get comfortable setting up the useEffect hook and write its 2 arguments without copying and pasting the code.&lt;/p&gt;

&lt;p&gt;If you want to see the finished code, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles" rel="noopener noreferrer"&gt;link&lt;/a&gt; and open the branch server-state.&lt;/p&gt;




&lt;h1&gt;
  
  
  Additional reading
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/hooks-reference.html" rel="noopener noreferrer"&gt;React hooks&lt;/a&gt; documentation: For a detailed explanation of the difference between all the available hooks.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=0ZJgIjIuY7U" rel="noopener noreferrer"&gt;useCallback hook&lt;/a&gt;: A short video tutorial to help you organize your useEffect code into smaller separated async functions.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Cover: Photo by &lt;a href="https://unsplash.com/@alexxsvch?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Alexey Savchenko&lt;/a&gt; on &lt;a href="/s/photos/city-night?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Video tutorial: &lt;a href="https://www.youtube.com/watch?v=0ZJgIjIuY7U&amp;amp;feature=emb_title" rel="noopener noreferrer"&gt;Learn useEffect In 13 Minutes - React Hooks Explained&lt;/a&gt; by &lt;a href="https://www.youtube.com/channel/UCFbNIlppjAuEX4znoulh0Cw" rel="noopener noreferrer"&gt;Web Dev Simplified&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Manage local state with useState hook</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:17:44 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/manage-local-state-with-usestate-hook-3j2k</link>
      <guid>https://dev.to/softwaredevacademy/manage-local-state-with-usestate-hook-3j2k</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/O6P86uwfdR0"&gt;
&lt;/iframe&gt;
&lt;em&gt;Video tutorial for this article&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's put into practice the concepts of state by using the useState hook to show and update information on the screen.&lt;/p&gt;


&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=UgEaJBz3bjY" rel="noopener noreferrer"&gt;Destructuring&lt;/a&gt;: Watch from the beginning when it mentions arrays until it mentions objects.&lt;/p&gt;


&lt;h1&gt;
  
  
  Intended result
&lt;/h1&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%2Fuploads%2Farticles%2Fjnhvremd1usswuyapd7l.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%2Fuploads%2Farticles%2Fjnhvremd1usswuyapd7l.png" alt="Alt Text"&gt;&lt;/a&gt; &lt;br&gt;
Figure 1: The components we will build, the one on the left without state and the one on the right with the state hook.&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%2Fuploads%2Farticles%2F8g5333gv02ruy75ndz9i.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%2Fuploads%2Farticles%2F8g5333gv02ruy75ndz9i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: The application hierarchy diagram.&lt;/p&gt;


&lt;h1&gt;
  
  
  Type of React Hooks
&lt;/h1&gt;

&lt;p&gt;React has many kinds of hooks, but today we will focus on the most basic yet most used scenario to keep the learning process simple.&lt;/p&gt;

&lt;p&gt;The most common used React Hooks to manage different kinds of state:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkc55wo8xrgi0l9xf7zqa.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%2Fuploads%2Farticles%2Fkc55wo8xrgi0l9xf7zqa.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This article will cover the first case, the &lt;code&gt;useState()&lt;/code&gt; variable for local state management.&lt;/p&gt;


&lt;h1&gt;
  
  
  Creating a useState() hook
&lt;/h1&gt;

&lt;p&gt;To create a &lt;code&gt;useState()&lt;/code&gt; state, follow these steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="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;setState&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setState&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="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;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;increase&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Increase counter&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now ignore, the button that calls a function, we will see it in greater detail on the article about buttons.&lt;/p&gt;

&lt;p&gt;Let's analyze the code line by line:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;import {useState} from "react"&lt;/code&gt; allows us to import the React Hook functionality.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const [state, setState] = useState(0);&lt;/code&gt; allows us to initialize the React Hook. 

&lt;ul&gt;
&lt;li&gt;The first value is the getter.&lt;/li&gt;
&lt;li&gt;The second value is the setter.&lt;/li&gt;
&lt;li&gt;Inside &lt;code&gt;useState()&lt;/code&gt;, we put the initial value. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{state}&lt;/code&gt; inside the JSX is used to call the getter and display the information on the screen.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;setState()&lt;/code&gt;is used to call the setter and update the information on the screen.&lt;/li&gt;
&lt;/ol&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%2Fuploads%2Farticles%2Fucvl4t8xm06j6arqywj0.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%2Fuploads%2Farticles%2Fucvl4t8xm06j6arqywj0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can create hooks using strings, numbers, booleans, arrays, and objects.&lt;/p&gt;

&lt;p&gt;Technically, it will allow you to use functions and classes, but those have some synchronization issues, so please stick with the basic data types mentioned above.&lt;/p&gt;




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

&lt;p&gt;By reading the theory article and practicing with the code example, it will be easy to understand how to use hooks.&lt;/p&gt;

&lt;p&gt;Now we can move to the next article: &lt;a href="https://dev.to/softwaredevacademy/button-events-in-react-5cml"&gt;Button events in React&lt;/a&gt;, to learn how to use events to manipulate the page using buttons.&lt;/p&gt;

&lt;p&gt;In you want to see a similar exercise, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles" rel="noopener noreferrer"&gt;link&lt;/a&gt; and open the branch state.&lt;/p&gt;




&lt;h1&gt;
  
  
  Additional reading
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/state-and-lifecycle.html" rel="noopener noreferrer"&gt;State and Lifecycle&lt;/a&gt;: The official documentation of React covering state management. Ignore the components that use classes because they are obsolete and focus only on components that use functions.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/hooks-reference.html" rel="noopener noreferrer"&gt;Hook API Reference&lt;/a&gt;: The official documentation of React covering the topic of React Hooks. Read it in case you want a in depth review of how hook works and more advance types of hooks.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Cover: Photo by &lt;a href="https://unsplash.com/@mael_balland?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Mael BALLAND&lt;/a&gt; on &lt;a href="/s/photos/hooks?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Video tutorial: &lt;a href="https://www.youtube.com/watch?v=O6P86uwfdR0" rel="noopener noreferrer"&gt;Learn useState In 15 Minutes - React Hooks Explained&lt;/a&gt; by &lt;a href="https://www.youtube.com/channel/UCFbNIlppjAuEX4znoulh0Cw" rel="noopener noreferrer"&gt;Web Dev Simplified&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Introduction to state management and React Hooks</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:15:46 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/introduction-to-state-management-and-react-hooks-285j</link>
      <guid>https://dev.to/softwaredevacademy/introduction-to-state-management-and-react-hooks-285j</guid>
      <description>&lt;p&gt;This article is about theory. Please read it before seeing the application in the next article.&lt;/p&gt;




&lt;h1&gt;
  
  
  How React update information on the screen?
&lt;/h1&gt;

&lt;p&gt;Before teaching about how to update information on the screen, we need to explain what React does behind the scenes to keep a balance between:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Showing information on the screen as fast as possible.&lt;/li&gt;
&lt;li&gt;Making your code easier to maintain.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each time you want to update information on the screen, React &lt;strong&gt;destroys&lt;/strong&gt; and &lt;strong&gt;recreates&lt;/strong&gt; a component to show the updated changes.&lt;/p&gt;

&lt;p&gt;This means any variable inside the component will be recreated using its initial value instead of the value you tried to update.&lt;/p&gt;




&lt;h1&gt;
  
  
  How React make information survive on the screen?
&lt;/h1&gt;

&lt;p&gt;To have variables that survive this destruction and recreation, we need to have a way to create those variables &lt;strong&gt;outside&lt;/strong&gt; the component.&lt;/p&gt;

&lt;p&gt;This is what state variables do. Each time you create a state variable, it will be created outside the component so it can survive each time the component is destroyed and recreated.&lt;/p&gt;




&lt;h1&gt;
  
  
  How React uses Hooks to manage the state?
&lt;/h1&gt;

&lt;p&gt;React Hooks are functional programming methods to create a state variable. In addition, it gives you a getter and a setter method to call this variable when you need to show its current value or modify it.&lt;/p&gt;




&lt;h1&gt;
  
  
  Interactive example
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://fe-react-state.web.app"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6pAArmmD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/izx7cfifsh89movphnph.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fe-react-state.web.app"&gt;React Hooks interactive example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click this link and follow its instructions to see how components with traditional variables and state variables behave. &lt;/p&gt;




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

&lt;blockquote&gt;
&lt;p&gt;In Ancient Chinese philosophy, yin and yang ("bright-black", "positive-negative") is a concept of dualism, describing how seemingly opposite or contrary forces may actually be complementary, interconnected, and interdependent in the natural world. - &lt;a href="https://en.wikipedia.org/wiki/Yin_and_yang"&gt;https://en.wikipedia.org/wiki/Yin_and_yang&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I hope that by seeing this cover picture and then reading the article for a second time, this concept of destruction and recreation is not only understood, but you accept it as a necessary evil to have projects that have high performance and are easier to maintain.&lt;/p&gt;

&lt;p&gt;With this theory and philosophy out of the way, we can move to React Hooks' application in the next article: &lt;a href="https://dev.to/softwaredevacademy/manage-local-state-with-usestate-hook-3j2k"&gt;Manage local state with useState hook&lt;/a&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;p&gt;Cover: &lt;a href="https://about.netflix.com/en/news/the-yin-yang-master-dream-of-eternity-arrives-on-netflix"&gt;The Yin-Yang Master: Dream Of Eternity&lt;/a&gt; by Netflix&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unmovable rock: Photo by &lt;a href="https://unsplash.com/@zoltantasi?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Zoltan Tasi&lt;/a&gt; on &lt;a href="/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Yin-Yang: Photo by &lt;a href="https://unsplash.com/@hrustall?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Дмитрий Хрусталев-Григорьев&lt;/a&gt; on &lt;a href="/s/photos/yin-yang?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Install external components using NPM</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:14:22 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/install-external-components-using-npm-3480</link>
      <guid>https://dev.to/softwaredevacademy/install-external-components-using-npm-3480</guid>
      <description>&lt;p&gt;Even if React is harder to learn than other JavaScript front-end frameworks, installing external components is where it all pays off.&lt;/p&gt;

&lt;p&gt;Because React is so popular, there are pre-built components for almost anything you can imagine. This makes your work way easier.&lt;/p&gt;




&lt;h1&gt;
  
  
  Intended result
&lt;/h1&gt;

&lt;p&gt;This is what we will have by the end of the article.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UqBqqEXQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytfak3d5r6r3445bny0c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UqBqqEXQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytfak3d5r6r3445bny0c.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: A basic YouTube video player using external components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a4IqxCco--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nct9fgxxwxpp3gjj6qia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a4IqxCco--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nct9fgxxwxpp3gjj6qia.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: App hierarchy chart.&lt;/p&gt;
&lt;h3&gt;
  
  
  Legend:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🟦 &lt;strong&gt;Blue&lt;/strong&gt;: Component created by us.&lt;/li&gt;
&lt;li&gt;🟨&lt;strong&gt;Yellow&lt;/strong&gt;: External component installed using NPM.&lt;/li&gt;
&lt;li&gt;◻️&lt;strong&gt;Grey&lt;/strong&gt;: Simple tags.&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;Let build this small YouTube player by first installing the external component called &lt;a href="https://www.npmjs.com/package/react-youtube"&gt;React Youtube&lt;/a&gt; by using a terminal window inside your project folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react-youtube
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once it is installed, we proceed to import it and utilize it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;YouTube&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-youtube&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;videoId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setVideoId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1_Aq5rQdPso&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;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;390&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;640&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;playerVars&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;autoplay&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;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;YouTube&lt;/span&gt; &lt;span class="na"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;videoId&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;videoId&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;

      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nx"&gt;setVideoId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1_Aq5rQdPso&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Golden Eye
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nx"&gt;setVideoId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rwDUWnOVf0c&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Tomorrow Never Dies
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's analyze the new lines of code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;import YouTube from "react-youtube"&lt;/code&gt; the package we installed using NPM. Note that it uses a route without dots or slashes because it is a global NPM package.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const options = {}&lt;/code&gt; A configuration file for the YouTube player (&lt;a href="https://github.com/tjallingt/react-youtube#usage"&gt;see the options available&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;YouTube/&amp;gt;&lt;/code&gt; The external component you imported.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opts={options}&lt;/code&gt; This is where we put the parameters we set up in the previous step.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;videoId={videoId}&lt;/code&gt; The most important element of the player: the &lt;strong&gt;state&lt;/strong&gt; that will change the video being played.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;br&gt;
Many React external components behave like Java classes with constructors and allow you to initialize the component using parameters.&lt;/p&gt;

&lt;p&gt;In the case of React YouTube is the parameter &lt;code&gt;options&lt;/code&gt;, but each external component will have their own property names to initialize, so always read the documentation of each component you install.&lt;/p&gt;




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

&lt;p&gt;With this knowledge of how to use external packages you have expanded greatly your ability to make useful front end projects. &lt;/p&gt;

&lt;p&gt;In the next article: &lt;a href="https://dev.to/softwaredevacademy/handling-multiple-pages-with-the-external-component-react-router-dom-l4a"&gt;Handling multiple pages with the external component React Router DOM&lt;/a&gt;, we will cover one of the most important external components of React, the &lt;strong&gt;React Router DOM&lt;/strong&gt;. This external component allows your project to behave like a traditional web page with multiple pages.&lt;/p&gt;

&lt;p&gt;If you want to see the finished code, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles"&gt;link&lt;/a&gt; and open the branch external-components.&lt;/p&gt;




&lt;h1&gt;
  
  
  Recommended external components
&lt;/h1&gt;

&lt;p&gt;Here is a short list of components so you can get started:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/react-router-dom"&gt;React Router DOM&lt;/a&gt;: Official NPM package of React Router DOM, a package that add multi page navigation to React.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/formik"&gt;Formik&lt;/a&gt;: Official NPM package of Formik to add pre-build forms instead of building and validating yourself.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/@fortawesome/react-fontawesome"&gt;FontAwesome&lt;/a&gt;: Official NPM package of Font Awesome to add its icon library.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/@material-ui/core"&gt;Material UI&lt;/a&gt;: Official NPM package of Material UI, a library of pre-designed components. &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://react-leaflet.js.org"&gt;React Leaflet&lt;/a&gt;: To embed maps in your apps.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/react-youtube"&gt;React YouTube&lt;/a&gt;: For embedding YouTube videos.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Cover picture: Photo by &lt;a href="https://unsplash.com/@lou_szabo?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Lajos Szabo&lt;/a&gt; on &lt;a href="/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Golden Eye music theme: By Tina Turner.&lt;/li&gt;
&lt;li&gt;Tomorrow Never Dies music theme: By Sheryl Crow.&lt;/li&gt;
&lt;li&gt;The World is Not Enough music theme: By Garbage.&lt;/li&gt;
&lt;li&gt;Die Another Day theme: By Madonna. &lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Creating a list of components using functional programming</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:13:16 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/creating-a-list-of-components-using-functional-programming-5aa7</link>
      <guid>https://dev.to/softwaredevacademy/creating-a-list-of-components-using-functional-programming-5aa7</guid>
      <description>&lt;p&gt;In this article we will automatize the creation of multiple components by using an external JSON file to hold our information.&lt;/p&gt;

&lt;p&gt;This will make our projects more organized because we make a clear separation of concerns.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The JSON contains our information.&lt;/li&gt;
&lt;li&gt;The components are the visual representation.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=h33Srr5J9nY" rel="noopener noreferrer"&gt;Arrow functions&lt;/a&gt;: A modern way to write functions in JavaScript. Is used all across React and in the map, filter, reduce methods.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/R8rmfD9Y5-c?t=118" rel="noopener noreferrer"&gt;Map function&lt;/a&gt;: A JavaScript method that allows to create a new array based on information from another array. (watch from 1:58 to 2:54)&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Intended result
&lt;/h1&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%2Fuploads%2Farticles%2Fyph808ehg2mh1nqny4qb.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%2Fuploads%2Farticles%2Fyph808ehg2mh1nqny4qb.png" alt="Alt Text"&gt;&lt;/a&gt; Figure 1: The same pet shot app but more organized behind the scenes.&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%2Fuploads%2Farticles%2Fvr4y7gz51nldwkki03wr.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%2Fuploads%2Farticles%2Fvr4y7gz51nldwkki03wr.png" alt="Alt Text"&gt;&lt;/a&gt; Figure 2: Hierarchy diagram. The element in the middle with dash lines is not a component, but an array holding components.&lt;/p&gt;




&lt;h1&gt;
  
  
  Anatomy of a map function
&lt;/h1&gt;

&lt;p&gt;Before we get started let's explain a bit about:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
The map function.&lt;/li&gt;
&lt;li&gt;
Arrays of components.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-map"&gt; &lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The map function
&lt;/h3&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%2Fuploads%2Farticles%2F64rua2yvof03lc1rykx6.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%2Fuploads%2Farticles%2F64rua2yvof03lc1rykx6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 3: A comparison between the map function with an arrow function inside vs. a traditional for loop.&lt;/p&gt;

&lt;p&gt;As you can see, the map function is just a shortcut to write more compact code. The less code you write, the less bugs you will have.&lt;/p&gt;

&lt;p&gt;&lt;span id="guide-array"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Arrays of components
&lt;/h3&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%2Fuploads%2Farticles%2F5ud5reinxtsizf7lvcm1.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%2Fuploads%2Farticles%2F5ud5reinxtsizf7lvcm1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 4: The contents of &lt;code&gt;ComponentArray&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As you can see, JavaScript arrays can literally hold anything, from strings, numbers, to even React 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%2Fuploads%2Farticles%2Fb8euz4odg76y9liw14b9.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%2Fuploads%2Farticles%2Fb8euz4odg76y9liw14b9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;For this exercise we will use a JSON file to create our list of components.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
JSON file.&lt;/li&gt;
&lt;li&gt;
App component.&lt;/li&gt;
&lt;li&gt;MyComponent&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-json"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  JSON file:
&lt;/h3&gt;

&lt;p&gt;Create a json file inside your &lt;code&gt;src/&lt;/code&gt; folder. Preferably inside a folder name &lt;code&gt;data/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Each object inside the array needs a key called &lt;code&gt;id&lt;/code&gt;. React needs this in order to keep track of each component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Puppy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"fileName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dog.jpg"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Whiskers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"fileName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cat.jpg"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Birdie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"fileName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cat-food.jpg"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;span id="guide-app"&gt; &lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  App component:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyJSON&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;./data/pets.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&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;./components/MyComponent&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ComponentArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;MyJSON&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;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fileName&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;));&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"grid"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ComponentArray&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's analyze the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;import MyJSON from "./data/pets.json"&lt;/code&gt;: We import our JSON.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const ComponentArray&lt;/code&gt; we create a variable to hold our array of components.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MyJSON.map()&lt;/code&gt; creates an array of components using the map function. This is where the &lt;a href="https://youtu.be/R8rmfD9Y5-c?t=118" rel="noopener noreferrer"&gt;Map function&lt;/a&gt; comes into play.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;MyComponent&amp;gt;&lt;/code&gt; is a copy of MyComponent, the map function will create as many components as the the json needs.&lt;/li&gt;
&lt;li&gt;Inside the JSX we put the &lt;code&gt;ComponentArray&lt;/code&gt; inside curly braces &lt;code&gt;{}&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-component"&gt; &lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  MyComponent:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fileName&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;imageObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../images/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;fileName&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;imageURL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;imageObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;article&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;imageURL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;article&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only change &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;imageObject&lt;/code&gt;: Is a variable to import image combining a location in our project folder with a prop received from a parent.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;require("../images/" + fileName)&lt;/code&gt;: require is a Node.js command to open a file from our project folder. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;imageURL&lt;/code&gt;: We create another variable to assign the specific key that has the image path. In this case &lt;code&gt;imageObject.default&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Finally, inside the JSX we use &lt;code&gt;{imageURL}&lt;/code&gt; in the &lt;code&gt;&amp;lt;img/&amp;gt;&lt;/code&gt; source property.&lt;/li&gt;
&lt;/ol&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%2Fuploads%2Farticles%2Fforrjds2ebznfht1q9ys.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%2Fuploads%2Farticles%2Fforrjds2ebznfht1q9ys.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




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

&lt;p&gt;Congratulations this conclude the articles for the first day of React.&lt;/p&gt;

&lt;p&gt;You can practice by refactoring your Cupcake website's product page and seeing how easy it is to organize the products. (only for the SDA students)&lt;/p&gt;

&lt;p&gt;You can take a break before moving to the articles intended for the next day, or &lt;a href="https://dev.to/softwaredevacademy/introduction-to-state-management-and-react-hooks-285j"&gt;click here&lt;/a&gt; to continue your studies.&lt;/p&gt;

&lt;p&gt;If want can to see the finished code, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles" rel="noopener noreferrer"&gt;link&lt;/a&gt; and open the branch create-list.&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits:
&lt;/h1&gt;

&lt;p&gt;Cover picture: Photo by &lt;a href="https://unsplash.com/@curology?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Curology&lt;/a&gt; on &lt;a href="/@el_alienx/likes?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Passing data to components using props
</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:09:46 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/passing-data-to-components-using-props-4lp0</link>
      <guid>https://dev.to/softwaredevacademy/passing-data-to-components-using-props-4lp0</guid>
      <description>&lt;p&gt;Props, a shorthand for properties, is a way to send information from a parent to a child. This allows components to look and behave differently based on properties that the parent sends.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.youtube.com/watch?v=UgEaJBz3bjY"&gt;Destructuring&lt;/a&gt;:&lt;/strong&gt; A way to extract the keys from an Object for easier use in JavaScript. (watch from 1:05)&lt;/p&gt;




&lt;h1&gt;
  
  
  Intended result
&lt;/h1&gt;

&lt;p&gt;This is what we are going to have by the end of the article.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0vgyY094--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/douydrpzl3tu5z5d7dcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0vgyY094--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/douydrpzl3tu5z5d7dcm.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: A webpage with the 3 copies of the same component, but with different titles and pictures.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IIsQgLSv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l75ul3goskiu9y67q07q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IIsQgLSv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l75ul3goskiu9y67q07q.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: The app hierarchy chart. Note that we are sending the title and the picture from &lt;code&gt;App.jsx&lt;/code&gt; to each copy of &lt;code&gt;MyComponent.jsx&lt;/code&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;In order to pass props, we need to modify the component that sends information called the parent, and the component that receives the information called the child.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pass props from the parent&lt;/li&gt;
&lt;li&gt;Receive and use the props in the children&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-parent"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pass props from the parent:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// App.jsx&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&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;./components/MyComponent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Images&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;DogPicture&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;./images/dog.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CatPicture&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;./images/cat.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;BirdPicture&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;./images/cat-food.jpg&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Puppy"&lt;/span&gt; &lt;span class="na"&gt;picture&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;DogPicture&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Whiskers"&lt;/span&gt; &lt;span class="na"&gt;picture&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;CatPicture&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Birdie"&lt;/span&gt; &lt;span class="na"&gt;picture&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;BirdPicture&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's analyze the code line by line:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add a property to the instance of the component. In this example, &lt;code&gt;title&lt;/code&gt; with the value &lt;code&gt;"Puppy"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If you want to use images, you need to import them first.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span id="guide-child"&gt; &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Receive and use the props in the children:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// MyComponent.jsx&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;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;picture&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"my-component"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;picture&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's analyze the code line by line:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Put the props send from the parent as arguments in the function parameters. Note that the props are wrapped around curly braces &lt;code&gt;{}&lt;/code&gt; This is called destructuring. Watch the pre-requisites video for more information.&lt;/li&gt;
&lt;li&gt;To show the text put the property inside the tags &lt;code&gt;&amp;lt;h2&amp;gt;{title}&amp;lt;/h2&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;To add a property to a tag, use the syntax &lt;code&gt;src={picture}&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zayD4QBd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdpuuvyio4km88zonyl2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zayD4QBd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdpuuvyio4km88zonyl2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusions
&lt;/h1&gt;

&lt;p&gt;You are close to finish the contents of the first day of React. Take a pause and practice what you have learned so far before going to the last &lt;a href="https://dev.to/softwaredevacademy/creating-a-list-of-components-using-functional-programming-5aa7"&gt;article&lt;/a&gt; of the day.&lt;/p&gt;

&lt;p&gt;Seriously, take a break. You have achieve a lot so far. But for the next topic I need you well rested in order to absorb a lot of new information. So take a break, then practice what we have done so far and then open the last link of the day.&lt;/p&gt;

&lt;p&gt;If want can to see the finished code, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles"&gt;link&lt;/a&gt; and open the branch passing-props.&lt;/p&gt;

&lt;p&gt;Finally, this is the TLDR (To Long Didn't Read) version of this article.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8k0oMJw3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pldvzawbqu4k5j21voob.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8k0oMJw3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pldvzawbqu4k5j21voob.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Cover: Photo by &lt;a href="https://unsplash.com/@annikamaria?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Annika Gordon&lt;/a&gt; on &lt;a href="/s/photos/sharing?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Dog picture: Photo by &lt;a href="https://unsplash.com/@karsten116?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Karsten Winegeart&lt;/a&gt; on &lt;a href="/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cat picture: Photo by &lt;a href="https://unsplash.com/@madhatterzone?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Manja Vitolic&lt;/a&gt; on &lt;a href="/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Bird picture: Photo by &lt;a href="https://unsplash.com/@alistairdent?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Alistair Dent&lt;/a&gt; on &lt;a href="/collections/1264592/freedom-zone-banner?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Create functional components in React</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:07:09 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/create-functional-components-in-react-59h5</link>
      <guid>https://dev.to/softwaredevacademy/create-functional-components-in-react-59h5</guid>
      <description>&lt;p&gt;One of the biggest benefits of using a front-end framework is making your application easier to manage by breaking down the page into smaller pieces called components.&lt;/p&gt;

&lt;p&gt;Think of components as boxes where you can put anything, including other smaller boxes, to organize your stuff. This article will explain how to create and import React components.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;JavaScript &lt;a href="https://www.youtube.com/watch?v=qgRUr-YUk1Q&amp;amp;t=11s" rel="noopener noreferrer"&gt;modules&lt;/a&gt;:&lt;/strong&gt; Know the basics about the import and export statements. Ignore the parts that mention Node.js and require().&lt;/p&gt;




&lt;h1&gt;
  
  
  Intended result
&lt;/h1&gt;

&lt;p&gt;This is what we will have by the end of the article.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F24ih82480bcv6160o9qk.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%2Fuploads%2Farticles%2F24ih82480bcv6160o9qk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: A simple page with 3 elements (components) on screen.&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%2Fuploads%2Farticles%2F93hxdg839e6z8zw9d0ch.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%2Fuploads%2Farticles%2F93hxdg839e6z8zw9d0ch.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: This is the app hierarchy chart. We will use it as a simplified version of the Activity diagram to see how the project looks behind the scenes.&lt;/p&gt;




&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;To create a component, follow these steps: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a folder called &lt;code&gt;components&lt;/code&gt; inside the &lt;code&gt;src&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Create a new file with the extension &lt;code&gt;.jsx&lt;/code&gt; inside your &lt;code&gt;components&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Create a function with the same name as your file using this pattern:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//MyComponent.jsx (the name of the file)&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;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"my-component"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello world&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fuploads%2Farticles%2F6jmlrqhd1ussf18egrof.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%2Fuploads%2Farticles%2F6jmlrqhd1ussf18egrof.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we are going to learn what each line of code does:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;export default&lt;/code&gt;: As the name says, it tells React this is the main component inside this file. You can export more than 1 component per file, but it is frown upon.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MyComponent()&lt;/code&gt;: Is the name of the component. You can change it to anything, but do not forget that it must be the same name as your &lt;code&gt;.jsx&lt;/code&gt; file. In the next chapter, we will learn what arguments we can put inside the parenthesis.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return()&lt;/code&gt;: Is the content to be displayed on the webpage. You can nest as many tags as you need, but only 1 can be on the root.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;className&lt;/code&gt;: This is the way to add a CSS class in React.&lt;/li&gt;
&lt;/ol&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%2Fuploads%2Farticles%2F3ozwmutv21a7yvngwhna.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%2Fuploads%2Farticles%2F3ozwmutv21a7yvngwhna.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Using a component
&lt;/h1&gt;

&lt;p&gt;To use a component, you need to do 2 things. Importing the component and using it inside the parent component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Importing:
&lt;/h3&gt;

&lt;p&gt;Open the component file where you want to insert your newly created component, for example, App.jsx, and follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;import&lt;/code&gt; on the top of the file followed by&lt;/li&gt;
&lt;li&gt;The name of the component. In this example &lt;code&gt;MyComponent&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;from&lt;/code&gt; determines the route.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"./components/MyComponent"&lt;/code&gt; a string with the &lt;a href="https://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/" rel="noopener noreferrer"&gt;relative&lt;/a&gt; path of the component.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Using the component inside another component:
&lt;/h3&gt;

&lt;p&gt;Inside the &lt;code&gt;return()&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;MyComponent/&amp;gt;&lt;/code&gt; you use the component like a HTML tag.&lt;/li&gt;
&lt;li&gt;As you can see, you can put as many copies (instances) of the same component. In another article we will learn a better way to make multiple copies.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// App.jsx&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&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;./components/MyComponent&lt;/span&gt;&lt;span class="dl"&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="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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&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%2Fuploads%2Farticles%2Fz212z79p99lb0v2l18cn.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%2Fuploads%2Farticles%2Fz212z79p99lb0v2l18cn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




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

&lt;p&gt;Now that you have learned how to create components and import them, you can move to the next chapter: &lt;a href="https://dev.to/softwaredevacademy/passing-data-to-components-using-props-4lp0"&gt;Passing information to components by using props.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In you want to see the finished code, open this &lt;a href="https://github.com/softwaredevacademy/sda-react-articles" rel="noopener noreferrer"&gt;link&lt;/a&gt; and open the branch create-component.&lt;/p&gt;

&lt;p&gt;Finally, this is the TLDR (To Long Did not Read) version of this article.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfj78mxs82z6ryg38blj.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%2Fuploads%2Farticles%2Fxfj78mxs82z6ryg38blj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Cover image: Photo by &lt;a href="https://unsplash.com/@mildlee?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Mildlee&lt;/a&gt; on &lt;a href="/s/photos/boxes?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>React Introduction</title>
      <dc:creator>Software Development Academy</dc:creator>
      <pubDate>Fri, 04 Jun 2021 12:02:33 +0000</pubDate>
      <link>https://dev.to/softwaredevacademy/react-introduction-3n3i</link>
      <guid>https://dev.to/softwaredevacademy/react-introduction-3n3i</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Tn6-PIqc4UM"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;em&gt;Video tutorial of this article&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hello to this quick course on React. The most in-demand JavaScript frontend library in the market for 2021. &lt;/p&gt;

&lt;p&gt;This series of articles are written for the &lt;a href="https://sdaproject.se"&gt;Software Development Academy&lt;/a&gt;, a joint venture between KTH and Novare Potential to re-skill people to become junior developers in Sweden.&lt;/p&gt;

&lt;p&gt;Although these articles are written for them, I will try to make them self-contained as possible so anybody can use them, even graduates from the SDA could come back and have a refresher on React in the future.&lt;/p&gt;




&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_cMb1rUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uha0jllw2lqd2vz3hswi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_cMb1rUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uha0jllw2lqd2vz3hswi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: An overview of the category of articles this course contains.&lt;/p&gt;

&lt;p&gt;To tackle this library's complexity, I will divide the articles into 5 categories. Each category has a few articles to expand on it.&lt;/p&gt;




&lt;h1&gt;
  
  
  Table of contents sorted by difficulty
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Getting started:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href=""&gt;React introduction&lt;/a&gt; (this article)
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/create-a-react-app-using-the-command-line-3e6p"&gt;Create a React app using the command line&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/create-functional-components-in-react-59h5"&gt;Create functional components in React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/passing-data-to-components-using-props-4lp0"&gt;Passing data to components using props&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/creating-a-list-of-components-using-functional-programming-5aa7"&gt;Creating a list of components using functional programming&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Making stuff interactive:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/introduction-to-state-management-and-react-hooks-285j"&gt;Introduction to state management and React Hooks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/manage-local-state-with-usestate-hook-3j2k"&gt;Manage local state with useState hook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/button-events-in-react-5cml"&gt;Button events in React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/form-events-in-react-4k8a"&gt;Form events in React&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handle multiple pages:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/install-external-components-using-npm-3480"&gt;Install external components using NPM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/handling-multiple-pages-with-the-external-component-react-router-dom-l4a"&gt;Handling multiple pages with the external component React Router DOM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/manage-server-state-with-useeffect-hook-3hbc"&gt;Manage server state with useEffect hook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manage large projects:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/manage-global-state-with-recoil-js-1h6k"&gt;Manage global state with Recoil.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  Table of contents sorted by category
&lt;/h1&gt;

&lt;p&gt;Beware, this approach will make you read certain articles that are harder to understand before others. Use it as a quick reference once you read the articles sorted by difficulty.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;📕 &lt;strong&gt;Introduction:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href=""&gt;React introduction&lt;/a&gt; (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/create-a-react-app-using-the-command-line-3e6p"&gt;Create a React app using the command line&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;📙 &lt;strong&gt;Components:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/create-functional-components-in-react-59h5"&gt;Create functional components in React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/passing-data-to-components-using-props-4lp0"&gt;Passing data to components using props&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/creating-a-list-of-components-using-functional-programming-5aa7"&gt;Creating a list of components using functional programming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/install-external-components-using-npm-3480"&gt;Install external components using NPM&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;📒 &lt;strong&gt;State management:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/introduction-to-state-management-and-react-hooks-285j"&gt;Introduction to state management and React Hooks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/manage-local-state-with-usestate-hook-3j2k"&gt;Manage local state with useState hook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/manage-server-state-with-useeffect-hook-3hbc"&gt;Manage server state with useEffect hook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/manage-global-state-with-recoil-js-1h6k"&gt;Manage global state with Recoil.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;📗 &lt;strong&gt;Event handling:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/button-events-in-react-5cml"&gt;Button events in React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/form-events-in-react-4k8a"&gt;Form events in React&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;📘 &lt;strong&gt;Manage large projects:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/softwaredevacademy/handling-multiple-pages-with-the-external-component-react-router-dom-l4a"&gt;Handling multiple pages with the external component React Router DOM&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




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

&lt;p&gt;This will be a long course, but I will try to break it down into small bite-size articles, so they don't become tiresome to read. Also, the contents will allow you to go directly to a particular topic when you need to remember it. To go to the first article, &lt;a href="https://dev.to/softwaredevacademy/create-a-react-app-using-the-command-line-3e6p"&gt;click here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By the way, this is chibi Godzilla. Sometimes it will appear on the articles to give additional information and even emotional support. On some occasions, he goes full evil and can be a bit mean, so be aware of it.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P0xyJSEc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zlhhz4zyq5zj44kv3co.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P0xyJSEc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zlhhz4zyq5zj44kv3co.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Cover picture: Photo by &lt;a href="https://unsplash.com/@lemonvlad?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Vladislav Klapin&lt;/a&gt; on &lt;a href="/s/photos/hello?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=Tn6-PIqc4UM&amp;amp;feature=emb_title"&gt;React in 100 seconds&lt;/a&gt;: By Fireship YouTube channel.&lt;/li&gt;
&lt;li&gt;Mini dinosaur: Icons made by &lt;a href="https://www.freepik.com" title="Freepik"&gt;Freepik&lt;/a&gt; from &lt;a href="https://www.flaticon.com/" title="Flaticon"&gt;&lt;/a&gt;&lt;a href="http://www.flaticon.com"&gt;www.flaticon.com&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
