<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: La Doppia Esse</title>
    <description>The latest articles on Forem by La Doppia Esse (@ladoppiaesse).</description>
    <link>https://forem.com/ladoppiaesse</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%2F923441%2Fca8502e8-2120-4d56-ad70-416e0b3bb9c0.jpeg</url>
      <title>Forem: La Doppia Esse</title>
      <link>https://forem.com/ladoppiaesse</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ladoppiaesse"/>
    <language>en</language>
    <item>
      <title>How to use the spread operator (...) in React</title>
      <dc:creator>La Doppia Esse</dc:creator>
      <pubDate>Wed, 01 Mar 2023 01:47:49 +0000</pubDate>
      <link>https://forem.com/ladoppiaesse/how-to-use-the-spread-operator-in-react-3oni</link>
      <guid>https://forem.com/ladoppiaesse/how-to-use-the-spread-operator-in-react-3oni</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Stumbled upon three dots or an ellipsis in JavaScript and wondered what on earth it means?&lt;/p&gt;

&lt;p&gt;Allow me to formally introduce you to the &lt;strong&gt;spread operator&lt;/strong&gt;! A handy JavaScript feature that makes your code simpler, compact, and more pleasant to write. The spread syntax might seem odd at first, but if you have the fundamentals of JavaScript down, it might be easier to learn than you think.&lt;/p&gt;

&lt;p&gt;In this post, I’ll teach you all about it and show you how to use spread with React. This is what we will cover:&lt;/p&gt;

&lt;p&gt;📍 What is the spread operator?&lt;br&gt;
📍 The spread operator syntax&lt;/p&gt;

&lt;p&gt;If you already know what the spread operator is, you can jump here: &lt;/p&gt;

&lt;p&gt;📍 How to use the spread operator to spread props in a React component&lt;br&gt;
📍 How to use the spread operator to update state in React&lt;br&gt;
📍 Pros and cons of using the spread syntax to spread props&lt;/p&gt;
&lt;h2&gt;
  
  
  What is the spread operator?
&lt;/h2&gt;

&lt;p&gt;Introduced with ES6 (the revision of JavaScript valid from 2015), the spread operator allows you to expand - or &lt;strong&gt;&lt;em&gt;spread&lt;/em&gt;&lt;/strong&gt; - arrays and objects into multiple elements. This can be useful when copying arrays or objects, or when working with a number of arguments or properties. In the context of React, the spread operator can be used to spread an object of props onto an element in a React component, making it easier to pass down props to child components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fntj8cg7nipbrfgf5bf4p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fntj8cg7nipbrfgf5bf4p.png" alt="Example use of the spread syntax" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Examples of the Spread Operator
&lt;/h2&gt;

&lt;p&gt;The spread operator is denoted by &lt;strong&gt;three dots&lt;/strong&gt;. Let’s have a look at some use cases for the spread syntax. &lt;/p&gt;
&lt;h3&gt;
  
  
  Creating shallow copies of arrays
&lt;/h3&gt;

&lt;p&gt;If we want to create a shallow copy of an array, we can easily do that using the spread operator. A shallow copy of an array allows you to work with the data in the copy without affecting the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;airbnbExperiences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Walk in the woods&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Local cooking class&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Guided tour&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// creating a shallow copy of the array using the spread syntax&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;airbnbExperiences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;airbnbExperiences&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// console.log(airbnbExperiences); &lt;/span&gt;

&lt;span class="cm"&gt;/* 
["Walk in the woods", 
 "Local cooking class", 
 "Guided tour of the city"]
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copying an array isn’t something you need to do every day, but let’s build on this syntax with the next example!&lt;/p&gt;

&lt;h3&gt;
  
  
  Concatenating arrays
&lt;/h3&gt;

&lt;p&gt;Another situation where the spread operator comes in handy is when we need to &lt;strong&gt;concatenate&lt;/strong&gt; two arrays or more arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;airbnbExperiences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Walk in the woods&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Local cooking class&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Guided tour of the city&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;moreAirbnbExperiences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Night diving&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Volcano hike&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Language class&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="c1"&gt;// concatenating the two arrays into a new one:&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;allAirbnbExperiences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
  &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;airbnbExperiences&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
   &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;moreAirbnbExperiences&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;allAirbnbExperiences&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
["Walk in the woods", 
 "Local cooking class", 
 "Guided tour of the city", 
 "Night diving", 
 "Volcano hike", 
 "Language class"]
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding elements to an object
&lt;/h3&gt;

&lt;p&gt;Similarly, we can spread the elements of an object and even add new elements using the spread syntax. This is a very powerful feature of the spread syntax and you will likely use it again and again in your daily Javascript chores!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;airbnbListings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;exp1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mario&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Walk in the woods&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Norway&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;exp2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gloria&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Local Cooking Class&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Italy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;updatedAirbnbListings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;airbnbExperiences&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;exp3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Night diving&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mexico&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;updatedAirbnbListings&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/* 
    {
   exp1: {
    host: "Mario",
    exp: "Walk in the woods",
    location: "Norway",
      },
   exp2: {
    host: "Gloria",
    exp: "Local Cooking Class",
    location: "Italy",
      },
   exp3: {
        host: "Tom", 
        exp: "Night diving", 
        location: "Mexico"
        }
  }
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Spreading an  array to function arguments
&lt;/h3&gt;

&lt;p&gt;We can also use the spread syntax to spread the elements of an array as separate arguments when calling a function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expPrice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;114&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;expPrice&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// 9  &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the function &lt;code&gt;Math.min()&lt;/code&gt; returns the lowest number within the &lt;code&gt;expPrice&lt;/code&gt; array. We are spreading the expPrice array into its arguments, as the  &lt;code&gt;Math.min()&lt;/code&gt; function takes a series of values and not an array. &lt;/p&gt;

&lt;p&gt;If you got the gist of how we can use the spread operator, let’s move to some practical use cases in React!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to use the spread operator to spread props in a React component&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The spread syntax can be very useful in React components, especially when dealing with props.  To thoroughly understand this section, you need to be familiar with React components, their parent-child relationships, and props. If you struggle to understand props or you simply want to refresh your knowledge, we wrote  &lt;a href="https://scrimba.com/articles/react-props/" rel="noopener noreferrer"&gt;this thorough tutorial on props&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Props is an object, and as we have just seen, an object can be spread into its multiple key-value pairs using the spread operator.&lt;/p&gt;

&lt;p&gt;Let’s build a small app to display data about Airnb Experiences. We start by building a component called &lt;code&gt;AirbnbListing&lt;/code&gt;, which receives &lt;code&gt;props&lt;/code&gt;. In this case, &lt;code&gt;props&lt;/code&gt; is an object containing information about the user:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;host&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;experience&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;location&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;price&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&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;AirbnbListing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Host: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;host&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;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Experience: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;experience&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;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Location: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&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;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Price: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&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;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;In our &lt;code&gt;App&lt;/code&gt;, we can render the &lt;code&gt;AirbnbListing&lt;/code&gt; component. Now, how do we pass the props to the component? We have two chances: &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Declaring the props one by one ⏰
&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;//Scenario 1: declare every prop&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;AirbnbListing&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/AirbnbListing&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;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mario&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;experience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Walk in the woods&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Norway&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="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="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AirbnbListing&lt;/span&gt;
        &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;experience&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;experience&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&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;h3&gt;
  
  
  2. Using the spread syntax to pass the whole props object in one easy go! ⚡
&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;//Scenario 2: using the spread operator&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;AirbnbListing&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/AirbnbListing&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;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mario&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;experience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Walk in the woods&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Norway&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="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="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AirbnbListing&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&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;What we render is exactly the same. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Flz77rkk6qtslzwr14ixo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Flz77rkk6qtslzwr14ixo.png" alt="Render of example code" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have followed so far, &lt;strong&gt;congratulations&lt;/strong&gt;! 🎉 Spreading props in React is not an easy concept and you may have wondered: if what we render is the same, should I actually use the spread operator? This is what we are tackling next.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Pros and cons of using the spread syntax to spread props&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are some pros and cons to using the spread syntax in React components. &lt;/p&gt;

&lt;p&gt;On one hand, it can save a lot of time and typing when you have a large number of props that you need to pass to a component, making the code less verbose. &lt;/p&gt;

&lt;p&gt;On the other hand, spreading props &lt;strong&gt;obscures the properties&lt;/strong&gt; we are passing to a component: to see them, we would need to shift to the file where props are declared, therefore making it difficult to see at a glance what props are being passed to a component. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note: in our code example, the props are declared in the same file for clarity, but this is not usually the case.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4hmmwljffrzjaqzeytos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4hmmwljffrzjaqzeytos.png" alt="Pros and cons of using the spread syntax to spread props" width="800" height="815"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ultimately, it is a matter of how you feel more comfortable. It is best to stick with the accepted standard of the company or the React project you are working for. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Verdict&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this article we have seen how useful the spread operator can be when working with props in React. When used together with other methods, such as the &lt;a href="https://scrimba.com/articles/react-list-array-with-map-function/" rel="noopener noreferrer"&gt;.map method&lt;/a&gt;, it can save precious time and make the code more concise. Still, it's always important to strike a balance between conciseness and readability! Use it at your own discretion and critically evaluate the specific situation. &lt;/p&gt;

&lt;p&gt;I hope you enjoyed the article! See you next time 💯&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Demystifying Linked Lists in JavaScript</title>
      <dc:creator>La Doppia Esse</dc:creator>
      <pubDate>Wed, 14 Dec 2022 22:48:54 +0000</pubDate>
      <link>https://forem.com/ladoppiaesse/demystifying-linked-lists-1bno</link>
      <guid>https://forem.com/ladoppiaesse/demystifying-linked-lists-1bno</guid>
      <description>&lt;p&gt;When I first encountered linked lists when learning JS, I felt hopeless. As a beginner, I really struggled to understand what they are used for and why we could not just use an array! As I didn’t want to leave a big gap in my knowledge, I took some time to demystify all about linked lists. This post is the result of such a process. I learnt, and I hope you will learn too: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What linked lists are and what they are made of&lt;/li&gt;
&lt;li&gt;Differences between linked lists and arrays&lt;/li&gt;
&lt;li&gt;Common uses of linked lists&lt;/li&gt;
&lt;li&gt;Code example&lt;/li&gt;
&lt;li&gt;Is a blockchain a linked list?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are linked lists?
&lt;/h2&gt;

&lt;p&gt;Linked lists are a common data structure in computer science. To be clear, an array is also a data structure, not a data type (for example, objects or booleans, or integers). Linked lists are made up of nodes, which are individual objects that contain two elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some &lt;strong&gt;data&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;A reference to the next node called &lt;strong&gt;pointer&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can imagine that in a linked list nodes are connected to each other in a chain-like structure.&lt;/p&gt;

&lt;p&gt;An important note here. Every linked list contains a &lt;strong&gt;head&lt;/strong&gt;, which is a pointer to the first node of the list. The head does not contain any data itself. At the end of the linked list, we find a &lt;strong&gt;tail&lt;/strong&gt;: as opposed to the head, the tail contains data, but it has no reference to the next node - because there is no next node! &lt;/p&gt;

&lt;p&gt;In JavaScript (and I guess in other programming languages) linked lists look like deeply nested objects (see the code snippet below). &lt;/p&gt;

&lt;h2&gt;
  
  
  The difference between linked lists and arrays
&lt;/h2&gt;

&lt;p&gt;The main difference between linked lists and arrays is that arrays are more of a &lt;strong&gt;static&lt;/strong&gt; data structure, whereas linked lists are more of a &lt;strong&gt;dynamic&lt;/strong&gt; data structure. I say ‘more of a’ static data structure because as you likely know, we can indeed modify the content of an array with methods such as push(), pop(), shift(), unshift(), and many more. Still, the addition or removal of data in a linked list is much more flexible than in an array.&lt;/p&gt;

&lt;p&gt;When inserting or deleting elements, linked lists are more efficient than arrays because they do not require any shifting or resizing of the data in the list. In an array, inserting or deleting an element at the beginning or middle of the list requires shifting all of the other elements in the array to make room for the new element or to fill the gap left by the deleted element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdaokf07rnu7axtfed7ku.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%2Fdaokf07rnu7axtfed7ku.png" alt="Demystifying Linked Lists"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Common uses of linked lists
&lt;/h2&gt;

&lt;p&gt;Using an array instead of a linked list will depend on the specifics of the application we are building. Linked lists are commonly used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storing the data of a list or queue, where elements are added and removed in a particular order. If you are into &lt;strong&gt;NFTs&lt;/strong&gt;, you are probably familiar with software that manage queues of users. Simply put, as one user gets to the checkout page, another one is allowed to enter the queue. The user at the checkout page will be removed from the linked list, whereas the new user will be inserted at the beginning of the linked list.&lt;/li&gt;
&lt;li&gt;Implementing an undo/redo system where each action performed by the user is stored in a linked list and can be undone or redone by moving backward or forward in the list. This is a feature we use every single day in text editors and so many other software. &lt;strong&gt;Blessed ctrl/cmd + Z (and ctrl/cmd + shift + Z)!&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Curious to see what a linked list looks like? Let’s write the code for a simple one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define the Node class. Each Node object has two properties:
// - data: the data stored in the node
// - next: a reference to the next node in the list
class Node {
  constructor(data) {
    this.data = data;
    this.next = null;
  }
}

// Define the LinkedList class. Each LinkedList object has two properties:
// - head: a reference to the first node in the list
// - length: the number of nodes in the list
class LinkedList {
  constructor() {
    this.head = null;
    this.length = 0;
  }

  // Define a method for adding a new node to the end of the list
  append(data) {
    // Create a new node
    const newNode = new Node(data);

    // If the list is empty, set the new node as the head
    if (this.head === null) {
      this.head = newNode;
    } else {
      // Otherwise, find the last node in the list and set its next property
      // to point to the new node
      let current = this.head;
      while (current.next !== null) {
        current = current.next;
      }
      current.next = newNode;
    }

    // Increment the length of the list
    this.length++;
  }
}

// Create a new LinkedList instance
const list = new LinkedList();

// Add some nodes to the list
list.append('first');
list.append('second');
list.append('third');
list.append('fourth');


console.log(list)

/* 
LinkedList 
{head: {data: "first", 
     next: {data: "second", 
         next: {data: "third", 
             next: {data: "fourth", 
                next: null}
                }
            }
        }, 
    length: 4}
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;LinkedList&lt;/code&gt;, the only method is &lt;code&gt;append (data)&lt;/code&gt;, which allows to append a new node. Other methods to manage the linked list are commonly included, e.g., to insert a node at the beginning or to remove a node at a certain index of the linked list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is a blockchain a linked list?
&lt;/h2&gt;

&lt;p&gt;If you have ever heard of a blockchain before, you most likely know that it is made up of &lt;strong&gt;interconnected blocks&lt;/strong&gt;. A block stores information (for example transactions) and is linked to the previous and the next one, therefore forming a chain of blocks. While both linked lists and blockchains involve the &lt;strong&gt;concept of linking data together&lt;/strong&gt;, the way that they do so is different. Linked lists are used to store and manipulate data in a linear sequence: as in the queue to buy NFTs, the linked list is dynamically updated and nodes (representing buyers) can be added or removed. On the other hand, blockchains are used to create a secure, ever-growing, and &lt;strong&gt;immutable record of data&lt;/strong&gt;: blocks cannot be removed as nodes in linked lists. Do not confuse the nodes of a linked list with the nodes of a blockchain. The latter are the computers that help secure the networks.&lt;/p&gt;

&lt;p&gt;In brief: &lt;strong&gt;&lt;u&gt;blockchains are not linked lists&lt;/u&gt;&lt;/strong&gt;, although they both involve the concept of linking some kind of data together.&lt;/p&gt;

&lt;p&gt;That's a wrap!&lt;/p&gt;

&lt;p&gt;Questions? Leave them below in the comments. I hope this article helped you to better understand linked lists. &lt;/p&gt;

&lt;p&gt;If you liked it, &lt;a href="https://twitter.com/LaDoppiaEsse" rel="noopener noreferrer"&gt;leave a follow on Twitter&lt;/a&gt; - I am looking forward to connecting with fellow beginner developers! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>linkedlists</category>
      <category>datastructure</category>
    </item>
    <item>
      <title>An introduction to React component props</title>
      <dc:creator>La Doppia Esse</dc:creator>
      <pubDate>Mon, 28 Nov 2022 20:59:19 +0000</pubDate>
      <link>https://forem.com/ladoppiaesse/an-introduction-to-react-component-props-508l</link>
      <guid>https://forem.com/ladoppiaesse/an-introduction-to-react-component-props-508l</guid>
      <description>&lt;p&gt;Props are short for properties and are one of React's most fundamental concepts! Since all React apps use props in one way or another it's essential you have an unshakable understanding of what they are and how to use them.&lt;/p&gt;

&lt;p&gt;Due to their unique behavior, props can be confusing and difficult to understand when you're first learning React. Don't worry though! We spent weeks assembling this comprehensive guide full of realistic examples and illustrations (there is even a prop quiz!) to help you on your way.&lt;/p&gt;

&lt;p&gt;In this article, you are going to learn:&lt;/p&gt;

&lt;p&gt;📍 What props are&lt;br&gt;
📍 Why they are important&lt;br&gt;
📍 How to receive them in a component&lt;br&gt;
📍 The difference between props and HTML attributes&lt;br&gt;
📍 How to destructure props&lt;br&gt;
📍 How to pass props of other data types, such as booleans and numbers&lt;/p&gt;

&lt;p&gt;Let's start by taking a closer look at React component and their relation to props.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a React component?
&lt;/h2&gt;

&lt;p&gt;Let’s start with an example from a website everyone is familiar with - YouTube. Although it is not built with React, YouTube still uses the concept of components.&lt;/p&gt;

&lt;p&gt;In React, a component is an &lt;strong&gt;independent and reusable bit of code&lt;/strong&gt; that makes up the building blocks of any React-built app.&lt;/p&gt;

&lt;p&gt;Imagine that you’re tasked to rebuild the YouTube homepage. Having a close look at it, you would easily notice that it is made of repeated elements:&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%2F7tlurs4k9ej0j3wm9e7o.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%2F7tlurs4k9ej0j3wm9e7o.png" alt="YouTube components 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, we have a &lt;code&gt;Videotile&lt;/code&gt; component. It is made by a thumbnail image, the title of the video, the name of the channel, the view count, and the timestamp:&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%2Fjbq59opskag2c1t6hoxr.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%2Fjbq59opskag2c1t6hoxr.png" alt="YouTube components 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first, you might be tempted to code each videotile separately, with its own data - a practice commonly referred to as &lt;strong&gt;hard coding&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;However, more than &lt;strong&gt;3 million videos&lt;/strong&gt; are uploaded to YouTube every single day. Surely YouTube developers aren’t spending their time coding up a new &lt;code&gt;Videotile&lt;/code&gt; instance every time someone uploads a new video!&lt;/p&gt;

&lt;p&gt;Instead, they coded a single &lt;code&gt;Videotile&lt;/code&gt; component that can &lt;strong&gt;automatically receive&lt;/strong&gt; the information it needs to display.&lt;/p&gt;

&lt;p&gt;At this point, you have figured out that it would be way better to code a single videotile component and, somehow, make it reusable. To make it reusable, the videotile component has to &lt;strong&gt;receive&lt;/strong&gt; data every time a new video is uploaded. Furthermore, the videotile must update itself when, for example, the view count increases and when the timestamp changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That’s where props come in&lt;/strong&gt;. Props allow us to make a component truly reusable, dynamically passing information between components as per our needs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Writing JSX
&lt;/h2&gt;

&lt;p&gt;To make use of props, it is important to understand how to write &lt;a href="https://reactjs.org/docs/introducing-jsx.html" rel="noopener noreferrer"&gt;JSX code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;JSX is a syntax extension of JavaScript. It allows us to describe how the user interface (i.e., what HTML elements) should look like by seamlessly integrating JavaScript code within HTML tags and vice versa.&lt;/p&gt;

&lt;p&gt;Let’s consider a simple component called &lt;code&gt;App&lt;/code&gt; that renders an H1 element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  const title = "Mr."
  const lastName = "Whiskerson"
  return (
    &amp;lt;h1&amp;gt;Hello {title} {lastName}!&amp;lt;/h1&amp;gt;
  )
}

ReactDOM.render(&amp;lt;App /&amp;gt;, document.getElementById("root"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the component, we declare two variables: &lt;code&gt;title&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When we’re inside JSX, curly braces give us a chance to “escape” back out of JSX and insert regular JavaScript values and expressions.&lt;/p&gt;

&lt;p&gt;If we were to just put &lt;code&gt;&amp;lt;h1&amp;gt;Hello title lastName!&amp;lt;/h1&amp;gt;&lt;/code&gt;, it would think we wanted the literal text title and lastName to be in the H1 tag. Surrounding those JS values with curly braces ensures the variables get evaluated for their values before inserting them into the text of the header.&lt;/p&gt;

&lt;h2&gt;
  
  
  Props in action - let’s create a contact component
&lt;/h2&gt;

&lt;p&gt;Okay - I assume that you now understand how props work in principle: it is better to have a flexible component that can receive information instead of a component that contains hard-coded information, making it non-reusable. With props, we can reuse components by passing in dynamic values instead of having to re-create those components with hard-coded data.&lt;/p&gt;

&lt;p&gt;Next, &lt;strong&gt;let’s make our first component&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;First, we will look at the inefficient way to code one (and explain how it is inefficient!), before refactoring it into a component that uses props.&lt;/p&gt;

&lt;p&gt;The component we will code is a contact card for cats! I hope you like cats as much as we do (&lt;a href="https://scrimba.com/about" rel="noopener noreferrer"&gt;Scrimba's mascot is a cat named Pumpkin 😺!&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// Components in React must always begin with capital letter
export default function App() {
  return (
    &amp;lt;div className="contacts"&amp;gt;
      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/mr-whiskerson.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Mr. Whiskerson&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(212) 555-1234&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;mr.whiskaz@catnap.meow&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/fluffykins.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Fluffykins&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(212) 555-2345&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;fluff@me.com&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/felix.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Felix&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(212) 555-4567&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;thecat@hotmail.com&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/pumpkin.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Pumpkin&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(0800) CAT KING&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;pumpkin@scrimba.com&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we add some CSS (that is why the divs have &lt;code&gt;className&lt;/code&gt;), this is what we render:&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%2Fer3qf19k7bmar7a5koqs.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%2Fer3qf19k7bmar7a5koqs.png" alt="cats contact cards"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why was this an &lt;strong&gt;inefficient way&lt;/strong&gt; to code a component?&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;App&lt;/code&gt; component, all the contact data is hard-coded! As we gather new cat contacts in our database, we have two options:&lt;/p&gt;

&lt;p&gt;Keep hardcoding data into our contact cards, losing valuable time 🚫&lt;br&gt;
Harvest the power of React and make a reusable component with props! ✅&lt;br&gt;
I hope we are on the same page - let’s go for the &lt;strong&gt;second option&lt;/strong&gt; 🙂&lt;/p&gt;

&lt;p&gt;First of all, we need to create a custom &lt;code&gt;Contact&lt;/code&gt; component. As we can see in the code snippet below, the data is still hardcoded, but we will take care of that very soon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Contact() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/mr-whiskerson.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Mr. Whiskerson&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(212) 555-1234&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;mr.whiskaz@catnap.meow&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/fluffykins.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Fluffykins&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(212) 555-2345&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;fluff@me.com&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/felix.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Felix&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(212) 555-4567&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;thecat@hotmail.com&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="contact-card"&amp;gt;
        &amp;lt;img src="./images/pumpkin.png" /&amp;gt;
        &amp;lt;h3&amp;gt;Pumpkin&amp;lt;/h3&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;(0800) CAT KING&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="info-group"&amp;gt;
          &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
          &amp;lt;p&amp;gt;pumpkin@scrimba.com&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can set our &lt;code&gt;App&lt;/code&gt; component to render multiple instances of our custom &lt;code&gt;Contact&lt;/code&gt; component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function App() {
  // App returns 4 instances of the Contact component
  return (
    &amp;lt;div className="contacts"&amp;gt;
      &amp;lt;Contact
        image="./images/mr-whiskerson.png"
        name="Mr. Whiskerson"
        phone="(212) 555-1234"
        email="mr.whiskaz@catnap.meow"
      /&amp;gt;
      &amp;lt;Contact
        image="./images/fluffykins.png"
        name="Fluffykins"
        phone="(212) 555-2345"
        email="fluff@me.com"
      /&amp;gt;
      &amp;lt;Contact
        image="./images/felix.png"
        name="Felix"
        phone="(212) 555-4567"
        email="thecat@hotmail.com"
      /&amp;gt;
      &amp;lt;Contact
        image="./images/pumpkin.png"
        name="Pumpkin"
        phone="(0800) CAT KING"
        email="pumpkin@scrimba.com"
      /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Does this syntax look familiar? It should!&lt;/p&gt;

&lt;p&gt;HTML elements have attributes. For example, an &lt;code&gt;img&lt;/code&gt; (image) tag can take the &lt;code&gt;src&lt;/code&gt; (source) attribute. Or an &lt;code&gt;a&lt;/code&gt; (anchor) tag can take an &lt;code&gt;href&lt;/code&gt; attribute that receives a link.&lt;/p&gt;

&lt;p&gt;To give an anchor tag a link, we use the &lt;code&gt;href&lt;/code&gt; attribute; to give the component a value, we use &lt;strong&gt;props&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;We can think of props like custom attributes for our custom React components. In the code snippet above, &lt;code&gt;Contact&lt;/code&gt; is our custom component, whereas &lt;code&gt;image&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;phone&lt;/code&gt;, and &lt;code&gt;email&lt;/code&gt; are &lt;strong&gt;props&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Even though the syntax is similar, HTML attributes and props are quite different: for example, where HTML attributes can only take strings as values, props in React can take any kind of JavaScript data type as a value. But more on that later!&lt;/p&gt;

&lt;h2&gt;
  
  
  Receiving props in a component
&lt;/h2&gt;

&lt;p&gt;Now we are all set up to receive properties in our &lt;code&gt;Contact&lt;/code&gt; component. An important note here: props can be used to pass data from a parent component (in this case, &lt;code&gt;App&lt;/code&gt;) to a child component (in this case, &lt;code&gt;Contact&lt;/code&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk5d9aykq0g1qf1i4me24.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%2Fk5d9aykq0g1qf1i4me24.png" alt="data flow in React"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is not possible to use props the other way around, i.e., to pass data from a child component to a parent component, as the flow of information in React is one way.&lt;/p&gt;

&lt;p&gt;There are ways to work around this limitation of one-way data flow in React, but they’re outside the scope of this article. If you want to have a deeper understanding of how this can be achieved, you can start &lt;a href="https://scrimba.com/articles/react-interview-questions/#how-do-you-pass-a-value-from-child-to-parent" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;As the component is a function called &lt;code&gt;Contact&lt;/code&gt;, we can &lt;strong&gt;receive an argument&lt;/strong&gt; - and that argument is props.&lt;/p&gt;

&lt;p&gt;In our case, props is an object that contains 4 key-value pairs: &lt;code&gt;image&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;phone&lt;/code&gt;, and &lt;code&gt;email&lt;/code&gt; are the keys, whereas the values are specified in the &lt;code&gt;App&lt;/code&gt; for each instance of the &lt;code&gt;Contact&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;As we are entering JavaScript, we need some curly braces.&lt;/p&gt;

&lt;p&gt;Instead of  &lt;code&gt;src="./images/mr-whiskerson.png"&lt;/code&gt;, we can now write &lt;code&gt;src={props.image}&lt;/code&gt;.  In this way, we are not hard coding the value (the location of the image), but we are using the value of the &lt;code&gt;props.image&lt;/code&gt; object!&lt;/p&gt;

&lt;p&gt;In the same way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name="Mr. Whiskerson”&lt;/code&gt; → &lt;code&gt;name={props.name}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;phone="(212) 555-1234"&lt;/code&gt; → &lt;code&gt;phone={props.phone}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;email="mr.whiskaz@catnap.meow"&lt;/code&gt; → &lt;code&gt;email={props.email}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can already see that our &lt;code&gt;Contact&lt;/code&gt; component is neater, less verbose, and it does not contain any cat-specific information - basically, &lt;strong&gt;we made it reusable&lt;/strong&gt;, which is what React props are all about!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// receiving props in a component

export default function Contact(props) {
  return (
    &amp;lt;div className="contact-card"&amp;gt;
      &amp;lt;img src={props.image} /&amp;gt;
      &amp;lt;h3&amp;gt;{props.name}&amp;lt;/h3&amp;gt;
      &amp;lt;div className="info-group"&amp;gt;
        &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
        &amp;lt;p&amp;gt;{props.phone}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div className="info-group"&amp;gt;
        &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
        &amp;lt;p&amp;gt;{props.email}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prop quiz!
&lt;/h2&gt;

&lt;p&gt;Still reading? Congratulations on making it this far! 💯&lt;/p&gt;

&lt;p&gt;Take a small break and have a sip of coffee ☕, because it’s time for a &lt;strong&gt;little prop (heh heh) quiz&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Would you be able to answer these questions? Take some moments to think about the answer before clicking Show answer:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. What do props help us accomplish?
&lt;/h4&gt;

&lt;p&gt;Answer: Simply put, props help us to make a component more reusable.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. How do you pass a prop into a component?
&lt;/h4&gt;

&lt;p&gt;Answer: You can pass props into a component using this syntax:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;MyAwesomeHeader title="???" /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;MyAwesomeHeader&lt;/code&gt; will be the name of the custom component, whereas &lt;code&gt;title&lt;/code&gt; will be a property of the component.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Can I pass a custom prop (e.g. &lt;code&gt;blahblahblah={true}&lt;/code&gt;) to a native HTML element (e.g. &lt;code&gt;&amp;lt;div blahblahblah={true}&amp;gt;&lt;/code&gt;)? Why or why not?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: No, because the JSX we use to describe native DOM elements will be turned into real DOM elements by React. And real DOM elements only have the properties/attributes specified in the HTML specification (which doesn't include properties like &lt;code&gt;blahblahblah&lt;/code&gt;). &lt;/p&gt;

&lt;h4&gt;
  
  
  4. How do I receive props in a component?
&lt;/h4&gt;

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

&lt;p&gt;`export default function MyAwesomeHeader(props) {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
    &amp;lt;header&amp;gt;
        {props.title}
    &amp;lt;/header&amp;gt;   
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;h4&gt;
  
  
  5. What data type is props when the component receives it?
&lt;/h4&gt;

&lt;p&gt;Props are objects. &lt;/p&gt;

&lt;h2&gt;
  
  
  Destructuring props
&lt;/h2&gt;

&lt;p&gt;The feature of &lt;strong&gt;destructuring&lt;/strong&gt; was introduced in ES6, the version of JavaScript introduced in 2015. Given that props are objects, they can be destructured as any other object in JS.&lt;/p&gt;

&lt;p&gt;In the React world, you are going to come across object destructuring a lot, so we are going to break it down. Let’s take for example a variable &lt;code&gt;cat&lt;/code&gt; with two properties, &lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// declaring an object with two properties

const cat = {
  firstName: "Mr.",
  lastName: "Whiskerson",
};

// destructuring the object with two properties
const { firstName, lastName } = cat;

console.log(lastName); // -&amp;gt; "Whiskerson"
console.log(cat.lastName); // -&amp;gt; "Whiskerson"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After destructuring it, we can write &lt;code&gt;firstName&lt;/code&gt; instead of &lt;code&gt;cat.firstName&lt;/code&gt;, thus slightly improving the readability. Both of them will still return the same value.&lt;/p&gt;

&lt;p&gt;Following on our example of the cat contact card, &lt;code&gt;props&lt;/code&gt; is an object with four properties: an image, a name, a phone number, and an email address. We can destructure props in the following way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//non-destructured props

export default function Contact(props) {
    return (
        &amp;lt;div className="contact-card"&amp;gt;
            &amp;lt;img src={props.image}/&amp;gt;
            &amp;lt;h3&amp;gt;{props.name}&amp;lt;/h3&amp;gt;
            &amp;lt;div className="info-group"&amp;gt;
                &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
                &amp;lt;p&amp;gt;{props.phone}&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="info-group"&amp;gt;
                &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
                &amp;lt;p&amp;gt;{props.email}&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

// destructured props

export default function Contact({ image, name, phone, email }) {
  return (
    &amp;lt;div className="contact-card"&amp;gt;
      &amp;lt;img src={image} /&amp;gt;
      &amp;lt;h3&amp;gt;{name}&amp;lt;/h3&amp;gt;
      &amp;lt;div className="info-group"&amp;gt;
        &amp;lt;img src="./images/phone-icon.png" /&amp;gt;
        &amp;lt;p&amp;gt;{phone}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div className="info-group"&amp;gt;
        &amp;lt;img src="./images/mail-icon.png" /&amp;gt;
        &amp;lt;p&amp;gt;{email}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that instead of &lt;code&gt;props.image&lt;/code&gt;, now that we destructured props, we must write &lt;code&gt;image&lt;/code&gt; only.&lt;/p&gt;

&lt;p&gt;Using prop destructuring is ultimately a &lt;strong&gt;personal choice&lt;/strong&gt;. In a scenario where the object has many properties, it may be reasonable to avoid destructuring at the cost of repeating the &lt;code&gt;props&lt;/code&gt;  keyword every time that a prop is used.&lt;/p&gt;

&lt;p&gt;On the other hand, when we do not have a lot of props as in our cat contact card, using destructuring could be helpful to highlight the props that are used in the component by improving the readability of the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing in non-string props
&lt;/h2&gt;

&lt;p&gt;The concept of props is very similar to the concept of HTML attributes, and with HTML attributes we always pass a string as the value (i.e., &lt;code&gt;src="./image.png"&lt;/code&gt;). It is tempting to think that you could only pass string values for props…but nope, we are in JavaScript world and we can pass everything we want - a boolean, a number, or even an object or a function.&lt;/p&gt;

&lt;p&gt;Passing in a non-string prop is pretty straightforward and uses a trick that we have already seen in this article: the use of curly braces.&lt;/p&gt;

&lt;p&gt;Imagine that we want to include in our Contact component an &lt;code&gt;isAvailable&lt;/code&gt; prop that we could later use to show or hide the contact card according to the cat’s availability to meet 🤣. In addition, we want to know how old the cat is, which we can indicate using a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// passing non-string props

export default function App() {
  return (
    &amp;lt;div className="contacts"&amp;gt;
      &amp;lt;Contact
        img="./images/mr-whiskerson.png" // string
        name="Mr. Whiskerson"
        phone="(212) 555-1234"
        email="mr.whiskaz@catnap.meow"
        isAvailable={true} // boolean
        age={7} // number
      /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By surrounding the boolean value or the number with curly braces, JSX interprets it as, respectively, a boolean and a number.&lt;/p&gt;

&lt;p&gt;As a teaser, it is also possible to pass functions as props. This feature is incredibly useful because, by passing a callback function as props, we can pass data from child to parent components!&lt;/p&gt;

&lt;h2&gt;
  
  
  The verdict
&lt;/h2&gt;

&lt;p&gt;The concept of props is at the core of React, and every React developer should have a &lt;strong&gt;prop&lt;/strong&gt;er (pun intended!) understanding.&lt;/p&gt;

&lt;p&gt;In this article, we have learned what props are, how they are used to code reusable components, how to pass data between components, and some useful tricks such as destructuring and passing non-string props.&lt;/p&gt;

&lt;p&gt;By now, I hope you feel confident enough to use props in your day-to-day React practice!&lt;/p&gt;

&lt;p&gt;If you want to practice more with props, I suggest checking out the &lt;a href="https://scrimba.com/learn/learnreact" rel="noopener noreferrer"&gt;Learn React Course at Scrimba&lt;/a&gt;. It is &lt;strong&gt;free&lt;/strong&gt;, taught by a great instructor, and has plenty of challenges and projects that will help you to learn React in an interactive way.&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>props</category>
      <category>beginners</category>
    </item>
    <item>
      <title>5 reasons most self-taught web developers burnout and quit</title>
      <dc:creator>La Doppia Esse</dc:creator>
      <pubDate>Fri, 09 Sep 2022 11:34:56 +0000</pubDate>
      <link>https://forem.com/ladoppiaesse/5-reasons-most-self-taught-web-developers-burnout-and-quit-jjm</link>
      <guid>https://forem.com/ladoppiaesse/5-reasons-most-self-taught-web-developers-burnout-and-quit-jjm</guid>
      <description>&lt;p&gt;Learning to code by yourself is hard, and the path is often not as straightforward as we imagined. Unforeseen challenges come up daily, and without the right motivation and support, it's easy to fall into despair.&lt;/p&gt;

&lt;p&gt;The scary truth? &lt;strong&gt;Most self-taught developers quit early from burnout before they even start building projects or applying for jobs&lt;/strong&gt; 😲&lt;/p&gt;

&lt;p&gt;In this article, we will go through the challenges, the pitfalls self-taught developers commonly face, and what steps you can take to keep learning and stay motivated.&lt;/p&gt;

&lt;p&gt;As a self-taught developer myself, I quit twice before getting it right! Coming from a PhD in Life Sciences, with no previous programming knowledge and way above the average age of a college freshman, I started again from the ground up. I made the best out of my failures and learned valuable lessons along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Lack of purpose
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HwXBl8FO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gzwfen2r1tru8ju3qlqk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HwXBl8FO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gzwfen2r1tru8ju3qlqk.png" alt="Lack of purpose when learning to program" width="880" height="667"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I started to learn web development for the first time, I had no clear purpose.&lt;/p&gt;

&lt;p&gt;I thought I could make a quick buck building websites and dove head first into web development. After an initial honeymoon phase of writing vanilla HTML, CSS, and JavaScript, it got more challenging, and I slowly lost motivation. &lt;strong&gt;Making money was not a strong enough reason for me.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To find your purpose, ask these questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why&lt;/strong&gt; do I want to learn web development?&lt;/li&gt;
&lt;li&gt;Do I want to build something on my own or rather be part of a team?&lt;/li&gt;
&lt;li&gt;What am I most passionate about web development?&lt;/li&gt;
&lt;li&gt;Am I a more technical or visual type of person?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you set a goal, finding a path and identifying the right learning resources for you becomes easier.&lt;/p&gt;

&lt;p&gt;If you want to be a front-end developer, maybe you should not start with PHP, for example. Instead, I would recommend you learn HTML, CSS, JavaScript, and React with &lt;a href="https://scrimba.com/learn/frontend"&gt;Scrimba's Frontend Developer Career Path&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Defining your purpose will boost motivation during the difficult moments you encounter and help you stay focused to achieve your long-term goals.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Self-doubt
&lt;/h2&gt;

&lt;p&gt;As a self-taught developer, it is normal to doubt yourself, especially at the beginning.&lt;/p&gt;

&lt;p&gt;If you've ever asked yourself one of these questions, you are not alone:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Am I smart enough to learn programming by myself? 🤔&lt;/li&gt;
&lt;li&gt;Who will ever hire me? 🤔&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/articles/too-old-to-be-web-developer/"&gt;Am I too old?&lt;/a&gt; 🤔&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When we cannot find an answer to these questions, we tend to give up after the initial momentum.&lt;/p&gt;

&lt;p&gt;With enough practice and motivation, anyone - from any background - can learn web development.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/podcast/hvac-tech-to-developer/"&gt;Dan&lt;/a&gt; was an air conditioning technician and landed his first job after 7 months of self-study.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/podcast/from-guitar-teacher-to-software-developer-after-scrimba/"&gt;John got a developer job&lt;/a&gt; after having worked as a guitar teacher.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/podcast/from-property-damage-restoration-to-web-developer/"&gt;Robert&lt;/a&gt; got his first job as a developer at 33!&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you are questioning if you're good enough, remember that everyone started somewhere - and very few people are outstandingly smart!&lt;/p&gt;

&lt;p&gt;You have probably noticed this yourself. When you started your first job, you likely were not as skilled as you are now.&lt;/p&gt;

&lt;p&gt;Did you study at university? I bet your first exam did not feel as good as the last one.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you are willing to put in the effort and consistency, you can't be in a worse place than you were yesterday. Celebrate every little win and acknowledge your progress.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Not thinking like a programmer
&lt;/h2&gt;

&lt;p&gt;One of the most challenging concepts to wrap your head around is how to "think like a programmer." It's an abstract concept, so let's look at two specific things you can try to improve your mindset and approach to code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Don't memorize or copy-paste code.
&lt;/h3&gt;

&lt;p&gt;Most self-taught developers make two common mistakes at the beginning.&lt;/p&gt;

&lt;p&gt;First, they tend to memorize most of the code they are learning, only to find out that they can't remember anything useful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ENMvvyaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wdiszj9zpskil6buiyng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ENMvvyaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wdiszj9zpskil6buiyng.png" alt="Don't memorize or copy paste code." width="880" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second issue that self-taught developers commonly encounter is getting stuck into a copy-paste loop: they follow the tutorial, think they understand and copy-paste the code in their text editor. Wrong 🙅🏻‍♂️! In the long term, copy-pasting code is as detrimental as memorizing code!&lt;/p&gt;

&lt;h3&gt;
  
  
  Breaking down complex problems
&lt;/h3&gt;

&lt;p&gt;I was making these mistakes myself until I found a book that changed my way of learning called &lt;a href="https://nostarch.com/thinklikeaprogrammer"&gt;Think like a programmer&lt;/a&gt; by Anton Spraul.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CDCAFMYA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78nrvzwnnm5h9p56drh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CDCAFMYA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78nrvzwnnm5h9p56drh5.png" alt="Think Like A Programmer by Anton Spraul" width="880" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the book, he clarifies that problem-solving is much more critical than any language's syntax - documentation is always available. It is much better to acquire an ''algorithmic mindset'' and know where to look or what to use to solve problems rather than memorizing syntax for a specific problem. &lt;a href="https://scrimba.com/podcast/be-a-librarian-not-an-encyclopedia-of-code-how-to-learn-and-teach-better-with-guil-hernandez/"&gt;You should be a librarian, not an encyclopaedia of code!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Writing code yourself allows you to understand the nitty-gritty and maximize your learning. I recently took the habit of writing pseudo-code before every project I undertake. It helps to feel like I'm building something myself and gives me the boost of confidence I need to get to the end.&lt;/p&gt;

&lt;p&gt;Most importantly, learning programming takes time: &lt;strong&gt;persistence and practice are the keys to success&lt;/strong&gt; 🏆.&lt;/p&gt;

&lt;p&gt;Allow yourself time to acquire foundational knowledge and do your best to apply it constantly.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Lack of support and community feeling
&lt;/h2&gt;

&lt;p&gt;Many people start studying programming as a way to shift careers or to pursue a new interest. It is likely that not so many people around you are doing the same.&lt;/p&gt;

&lt;p&gt;I first started to code with a 10$ online course. We had a community Facebook group that was poorly taken care of and soon transformed into a spam links dumpster. The only course teacher was most of the time unavailable to answer questions. Having no one around I could relate to when I was &lt;strong&gt;overwhelmed and frustrated&lt;/strong&gt; was discouraging and one of the reasons why I initially gave up.&lt;/p&gt;

&lt;p&gt;Nowadays, more and more e-learning platforms realize the importance of a thriving community.&lt;/p&gt;

&lt;p&gt;If you are looking for an inclusive and welcoming community for aspiring junior developer I recommend the &lt;a href="https://scrimba.com/community"&gt;Scrimba community&lt;/a&gt;. Alternatively, look around!&lt;/p&gt;

&lt;p&gt;Here are what I think make a supportive community that help you avoid burnout:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Members &lt;strong&gt;spread positivity&lt;/strong&gt; and are recognized for their engagement&lt;/li&gt;
&lt;li&gt;Teachers and community managers are available to answer your questions&lt;/li&gt;
&lt;li&gt;Feedback from members is well-received and valued&lt;/li&gt;
&lt;li&gt;Events are organized (for example, coding challenges or giveaways)&lt;/li&gt;
&lt;li&gt;Spam and aggressive behaviors are kept at bay&lt;/li&gt;
&lt;li&gt;Local, offline meet-ups are organised when possible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, reach out to your developer friends or acquaintances - there is a high chance that you know at least a couple - and ask them questions!&lt;/p&gt;

&lt;p&gt;You will notice that &lt;strong&gt;the developer community is very open&lt;/strong&gt; and willing to help people that are starting out&lt;/p&gt;

&lt;p&gt;Joining local and online communities will make the journey to become a developer and land a job much more enjoyable!&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Lack of an online coding presence and a portfolio
&lt;/h2&gt;

&lt;p&gt;Another common mistake beginner developers make is keeping their awesome projects on their computers, and once they are ready to apply for jobs, they realize that they have nothing to show.&lt;/p&gt;

&lt;p&gt;You have spent hours building a wonderful website, a shining Chrome extension or a JavaScript Pomodoro timer. Why on Earth wouldn't you &lt;strong&gt;share it with others?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This way, people - including your next employer - can see you have been actively learning, building, and sharing with others.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/9eMp8l4WEpE"&gt;
&lt;/iframe&gt;
&lt;br&gt;
There are several ways to do that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload your projects on GitHub and keep them up-to-date.&lt;/li&gt;
&lt;li&gt;Share your progress on a YouTube channel or your blog.&lt;/li&gt;
&lt;li&gt;Have a portfolio website - you can learn how to build one &lt;a href="https://scrimba.com/learn/portfolio"&gt;with this free Scrimba course&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The verdict
&lt;/h2&gt;

&lt;p&gt;Becoming a self-taught developer is a windy journey, and it is common to struggle and feel overwhelmed.&lt;/p&gt;

&lt;p&gt;Setting up a clear purpose or goal and shifting your learning mindset is essential to overcoming these challenges. No matter where in the journey you are, you will always face self-doubt and encounter issues: in this regard, joining a local or online community of developers will make you feel comfortable and less lonely.&lt;/p&gt;

&lt;p&gt;Finally, show off your hard work and share your projects with the world. Motivation and persistence will be your two best companions.&lt;/p&gt;

</description>
      <category>career</category>
      <category>webdev</category>
      <category>advice</category>
    </item>
  </channel>
</rss>
