<?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: Austin</title>
    <description>The latest articles on Forem by Austin (@abflatiron).</description>
    <link>https://forem.com/abflatiron</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%2F841195%2Fd975031a-0500-45c3-a992-4da4f0fd3794.png</url>
      <title>Forem: Austin</title>
      <link>https://forem.com/abflatiron</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abflatiron"/>
    <language>en</language>
    <item>
      <title>Deploy a Basic React Project to Amazon AWS EC2</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Mon, 17 Apr 2023 22:05:40 +0000</pubDate>
      <link>https://forem.com/abflatiron/deploy-a-basic-react-project-to-amazon-aws-ec2-1aoh</link>
      <guid>https://forem.com/abflatiron/deploy-a-basic-react-project-to-amazon-aws-ec2-1aoh</guid>
      <description>&lt;p&gt;So you want to deploy your React application to AWS... &lt;/p&gt;

&lt;p&gt;This guide provides a basic overview of configuring and deploying an Amazon Web Service (AWS) Elastic Compute Cloud (EC2) instance and deploying an existing React application on a github repo using git. &lt;/p&gt;

&lt;h2&gt;
  
  
  Instructions to Provision an EC2 Instance:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;br&gt;
Create an AWS account: &lt;a href="https://aws.amazon.com/" rel="noopener noreferrer"&gt;https://aws.amazon.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;br&gt;
Navigate to your "Console Home" dashboard, which should look like this: &lt;/p&gt;

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

&lt;p&gt;(you can also customize the appearance of your "Console Home" &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;From your "Console Home" dashboard, select "Launch a Virtual Machine" &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%2Fwckbfy6fhib1j4rb7et9.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%2Fwckbfy6fhib1j4rb7et9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will take you to the EC2 Launch an Instance page from where you will configure your virtual machine. &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%2F8p408l0jx79rnch7gbvx.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%2F8p408l0jx79rnch7gbvx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's pause for a moment here and give an overview of what the "Launch an instance" dashboard provides. &lt;/p&gt;

&lt;p&gt;From this page, AWS provides you with the ability to customize what you need (or want) your cloud machine's specifications to be. Here, you'll be able to select an operating system (OS), the size of hardware (both storage size and compute size). &lt;/p&gt;

&lt;p&gt;Put more analogously, it's akin to going to Apple.com to spec out a mac (Model, Color, Processor, SSD, etc.) - but at a far more granular level. &lt;/p&gt;

&lt;p&gt;Let's keep going... &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;br&gt;
Name your web server. In this example, I've named my instance "Blog React App". &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%2Fyrurowwx4927azkhnqgm.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%2Fyrurowwx4927azkhnqgm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt;&lt;br&gt;
Select an Amazon Machine Image (AMI) - what OS (and other software) you want the machine to have from the jump. There are several "standard" options: Amazon Linux, Ubuntu, Windows, Red Hat. For this example, I selected Ubuntu. You can also search for other AMIs that have been created to support AWS users, with various pre-configured software out of the box. &lt;/p&gt;

&lt;p&gt;Additionally, as you become a regular user of AWS and find yourself developing regularly with js or python on ubuntu or linux  machines, you can create custom AMIs to your specifications so that you can create (or "spin-up") new EC2 instances for new development work. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt;&lt;br&gt;
Select and Instance Type. This is your processor. With a new account, AWS provides their t2.micro instance for free (there is a limit on this so make sure to check your usage!). Depending on what you're doing on the instance, you may need a larger instance type. &lt;/p&gt;

&lt;p&gt;Since we're just deploying a basic React app, I've selected the base t2.micro option. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt;&lt;br&gt;
You are advised to create a Key pair. This is a security step for authenticating the user and AWS instance. &lt;/p&gt;

&lt;p&gt;I've created a key, and titled it "blog-key" &lt;br&gt;
Since I'm using a mac, I've chosen the "RSA" Key pair type and .pem format since I plan to SSH into the instance from a terminal on my laptop. &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%2F1s46ymde9wvyg7f9ec8v.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%2F1s46ymde9wvyg7f9ec8v.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you click "Create new Key pair", the .pem file will automatically download onto your laptop. &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%2Fpe4uzkwa02vi8w3032jr.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%2Fpe4uzkwa02vi8w3032jr.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can save this file anywhere on your laptop, but you'll need to reference the path to the file in just a bit. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next is configuring the security group. This is a challenge for many AWS users, seasoned and new alike. AWS gives you the ability to permit the traffic you want to allow to your EC2 instance. &lt;/p&gt;

&lt;p&gt;If this is your first time setting up EC2, you'll be prompted to create a security group. A security group is AWS's name for the network settings you want to configure together that will be applied to a specific instance. &lt;/p&gt;

&lt;p&gt;For this instance, I'll go ahead an select "create a new security group". I want to be able to SSH into the instance, so I've selected "Allow SSH traffic from" and set the IP range to anywhere. &lt;/p&gt;

&lt;p&gt;I also want the instance accessible after I've deployed my React app, so I'm also going to allow HTTP and HTTPS access from the internet. &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%2F39f0afhkraw2a33op8el.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%2F39f0afhkraw2a33op8el.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NB: I'm not an expert on network settings, and setting IP ranges and opening ports for access is itself another area of learning. Since this blog post is about getting a bare bones EC2 instances set up and running with an app, I don't dive deeply into network and security settings. However, if you plan on deploying an app for production or with sensitive data, you should be advised to take care in setting your network settings and security.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;**We will not be configuring Storage or adding any Advanced Details &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click the orange "Launch Instance" button &lt;/p&gt;

&lt;p&gt;It may take a few seconds to a few minutes for the instance to successfully launch and be available (keep in mind, your request for an EC2 instance has to be sent over your internet network to AWS, which then has to "provision" that machine with the specifications. This can take some time). &lt;/p&gt;

&lt;p&gt;If the provisioning is successful, you should see this: &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 10:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click on "Instances" - this will take you to another dashboard that shows you all the current instances running under your account. &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%2Fd860g8z76wt3q5hkmsxu.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%2Fd860g8z76wt3q5hkmsxu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(we only see one instance running - the one we just set up - which is accurate for my account) &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 11:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click on the "instance id" - that will take you to a new page that will show you information about just that specific instance. &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%2Froajnjr81iqixi517wnd.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%2Froajnjr81iqixi517wnd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This page shows you the IP addresses and various other details about the instance. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 12:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click "Connect". This will take you to the "Connect to instance" page where you'll find information on how to connect to the instance from your laptop. &lt;/p&gt;

&lt;p&gt;We're going to going to use SSH to connect, so we'll click on that tab: &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%2Fbqe7673sa16d34oinsu8.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%2Fbqe7673sa16d34oinsu8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can follow the instructions on the page, or do the following; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open a command terminal on your computer&lt;/li&gt;
&lt;li&gt;Find your private key file (the .pem file we created earlier) &lt;/li&gt;
&lt;li&gt;Run this command: chmod 400 blog-key.pem (you would change "blog-key.pem" to the name of your pem file) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the command is successful, you should see a new command line returned &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%2F45idv1kns536pekm4u22.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%2F45idv1kns536pekm4u22.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we're ready to connect to our EC2 instance! &lt;/p&gt;

&lt;p&gt;Get the Public DNS address from the Connect page. &lt;/p&gt;

&lt;p&gt;Then, in your command terminal, use this ssh command: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;ssh -i "blog-key.pem" ubuntu@ec2-13-57-255-249.us-west-1.compute.amazonaws.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the SSH connection is successful, you should expect to see something like this: &lt;/p&gt;

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

&lt;p&gt;Ok. Now we're in the instance, but we're not done yet. &lt;/p&gt;

&lt;p&gt;The instance you've been provisioned has ubuntu installed on it, but it won't have all the software you need on it to run a React application. This is going to be true for any other software you might want to run on this or any other instance. Remember how you had to install Node, Ruby, Python to be able to run it on your laptops? The same is true on EC2. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;btw: you can navigate the EC2 instance just as you would your local machine on the command line (e.g. cd, ls, mkdir, etc.)&lt;/p&gt;

&lt;p&gt;To end an SSH session from the client side, you can type these keys in sequence: ,  + , then :&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's a short checklist of the packages we'll need: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;apt &lt;/li&gt;
&lt;li&gt;git &lt;/li&gt;
&lt;li&gt;Node (and npm) &lt;/li&gt;
&lt;li&gt;nginx &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's start by checking a few things. &lt;/p&gt;

&lt;p&gt;Run command: &lt;code&gt;sudo apt update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's break this down:&lt;/p&gt;

&lt;p&gt;The prefix "sudo" tells the instance that you're executing a command as "root" and we're updating "apt" which is ubuntu's package management tool. &lt;/p&gt;

&lt;p&gt;Here are the official description and reference links: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sudo: &lt;a href="https://www.sudo.ws/about/intro/" rel="noopener noreferrer"&gt;Sudo&lt;/a&gt; (su “do”) allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments.&lt;/li&gt;
&lt;li&gt;apt: apt (&lt;a href="https://manpages.ubuntu.com/manpages/trusty/en/man8/apt.8.html" rel="noopener noreferrer"&gt;Advanced Package Tool&lt;/a&gt;) is the command-line tool for handling packages. It provides a command line interface for the package management of the system. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;git should come out of the box on the ubuntu, but we can check if it's there with this command: &lt;code&gt;git --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If git is installed, you'll see the version number; otherwise you'll get a message to install git. &lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;sudo apt install git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Install the webserver nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install nginx -y
nginx -v
sudo systemctl restart nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, let's install node and npm. I had some trouble running the standard install command, and found this recommendation on &lt;a href="https://stackoverflow.com/questions/47371904/e-unable-to-locate-package-npm" rel="noopener noreferrer"&gt;stakoverflow&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;curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you'd like, go ahead and check that the packages are installed and that the versions are correct:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Ok! Now to get our project onto the server (our EC2) &lt;/p&gt;

&lt;p&gt;Navigate to this directory: &lt;br&gt;
&lt;code&gt;cd /var/www/html/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We're going to add our project here. &lt;/p&gt;

&lt;p&gt;Run a git clone command to clone your React repo into this directory: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone &amp;lt;github http address&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, cd into the project directory. &lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the installation is complete, you can start the React application! &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the build is successful, you should see something like this: &lt;/p&gt;

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

&lt;p&gt;Of course, we now want to see the site from a web browser! &lt;/p&gt;

&lt;p&gt;Let's go back to our instance summary dashboard. &lt;/p&gt;

&lt;p&gt;Find the Public IPv4 address at the top of the page: &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%2Fnefqxfyi59uioo03a1na.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%2Fnefqxfyi59uioo03a1na.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy and paste that address into a browser and see if we get our React app: &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%2Fqwo7e7j01o7kny2t6m2s.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%2Fqwo7e7j01o7kny2t6m2s.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We're hitting the nginx welcome page, and &lt;em&gt;not&lt;/em&gt; our React app! However, seeing this page means that the web server is running correctly AND we're able to access the instance from the world wide web! &lt;/p&gt;

&lt;p&gt;To get to the React app, we need to specify the &lt;strong&gt;port&lt;/strong&gt; that the app is running on in the web address. In our case, it's port 3000. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://13.57.255.249:3000/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;However, this address will error out. &lt;/p&gt;

&lt;p&gt;This is because we have not allowed that port to be publicly accessible in our network settings. &lt;/p&gt;

&lt;p&gt;We have to go back to our instance summary page, and select the "Security tab" &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%2Fciudlocj4wp5wtdwxijw.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%2Fciudlocj4wp5wtdwxijw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the "Security group" - this will take you to the config page for the security group. &lt;/p&gt;

&lt;p&gt;Click "Edit Inbound Rules", then on the edit page, Click "Add rule" &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%2F1wxevlytqdx95x0emfu2.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%2F1wxevlytqdx95x0emfu2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type&lt;/strong&gt; Select "Custom TCP"&lt;br&gt;
&lt;strong&gt;Port Range&lt;/strong&gt; Type "3000"&lt;br&gt;
&lt;strong&gt;Source&lt;/strong&gt; Select "Anywhere-IPv4" &lt;/p&gt;

&lt;p&gt;Then the orange "Save Rules". &lt;/p&gt;

&lt;p&gt;Now, try navigating again to &lt;code&gt;http://13.57.255.249:3000/&lt;/code&gt;in your browser (note: it could take a brief moment for the rules to update) &lt;/p&gt;

&lt;p&gt;You should see your app, which in this example, is the out of box new React application welcome page: &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%2Fl99gg2m7279s7ts7fvxt.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%2Fl99gg2m7279s7ts7fvxt.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>react</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What are Elements?</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Sun, 19 Mar 2023 20:52:45 +0000</pubDate>
      <link>https://forem.com/abflatiron/what-are-elements-1hpf</link>
      <guid>https://forem.com/abflatiron/what-are-elements-1hpf</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array1 = [1, 4, 9, 16];


// Pass a function to map
const map1 = array1.map(x =&amp;gt; x * 2);


console.log(map1);
// Expected output: Array [2, 8, 18, 32]

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

&lt;/div&gt;



&lt;p&gt;What is the ‘x’ in the map method above?&lt;/p&gt;

&lt;p&gt;When I started learning to code, this was the single biggest head scratcher that I had to contend with as I was trying to understand the syntax of array methods.&lt;/p&gt;

&lt;p&gt;The ‘x’ in the above example is referred to as the “element” - the current element being processed in the array.&lt;/p&gt;

&lt;p&gt;So, what is an element? And why is it represented as an ‘x’? And why is that position occupied by a different letter (or word?!) in other examples of the same method usage?&lt;/p&gt;

&lt;p&gt;The definition provided by the MDN documentation for the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;Array.prototype.map()&lt;/a&gt; isn't all that great in explaining exactly what an "element" is... here's their definition:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#element:&lt;br&gt;
   #The current element being processed in the array.&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;em&gt;I hadn't realized that MDN was so into tautologies...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, this definition is probably very clear to seasoned developers who just need the quick refresh on what they're looking at. That's not usually the case for people starting out in their coding journeys.&lt;/p&gt;

&lt;p&gt;Put simply (and perhaps not particularly accurately), the letter or word put in the place for the "element" represents the specific position object/variable that the method is acting on for the iteration.&lt;/p&gt;

&lt;p&gt;In a map function, we give the function an array to "map" through, meaning, we want the method to go through each instance/variable (re:element) in that array, one-by-one, and do something to it. For the map function to go through each of the items in the array, it needs to be able to "hold" that particular instance (or element) as it performs the map job that we want it to do for our code.&lt;/p&gt;

&lt;p&gt;Let's go back to our original map example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// we have array1 that we want to perform a map function on.
const array1 = [1, 4, 9, 16];


// we write the map function:
const map1 = array1.map(x =&amp;gt; x * 2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;note the "x" - as the map function literally "maps" through Array1, going one-by-one through the array, the "x" we defined as the element is the first array position, with the value of 1&lt;br&gt;
then "x" is the second array position, with the value of 4, and keeps going until it reaches the end of the array.&lt;/p&gt;

&lt;p&gt;let's visualize in more detail:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array1 = [1, 4, 9, 16];
const map1 = array1.map(x =&amp;gt; x * 2)


Array1[0] :     1 =&amp;gt; 1 * 2  = map1[0] = 2
Array1[1] :     4 =&amp;gt; 4 * 2  =  map1[1] = 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…and so forth…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(map1);
// Expected output: Array [2, 8, 18, 32]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But guess what? You can give the element any value you want! You could name the element "itSortaMakesSenseNow" * and it'll still work! (Try it out for yourself on &lt;a href="//replit.com"&gt;Replit&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;const map1 = array1.map(itSortaMakesSenseNow =&amp;gt; itSortaMakesSenseNow * 2) 

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

&lt;/div&gt;



&lt;p&gt;*NB: This is NOT recommended.&lt;/p&gt;

&lt;p&gt;The same thing is true in Ruby syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def map_through_array
   array = [1,2,3]
   array.map { |n| n * 2 }
end
# output:  [2, 4, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could instead sub out n for “number”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def map_through_array
   array = [1,2,3]
   array.map { |number| number * 2 }
end
# output:  [2, 4, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So you have a fair bit of flexibility when it comes to how you name your elements. Certainly for the array methods at our disposal (i.e. Array.find(), Array.filter() ) you can name the element however you want. &lt;/p&gt;

&lt;p&gt;That said, you do want to keep your code reader friendly, and when you do see well-written code, you’ll find that the elements are typically single letters (minimizing the amount of bits in the code) and relatively intuitive for the function. In the examples above, since we were mapping through an array of numbers to perform a mathematical function, using the element name “number” or “n” for short makes sense. It’s best not to use a long string such as “itSortaMakesSenseNow”. We’d probably come to regret that later. &lt;/p&gt;

&lt;p&gt;Additionally, there are conventions that already exist, are considered a standard, and should be generally respected by coders. &lt;/p&gt;

&lt;p&gt;A very good example is when building migration files for Ruby on Rails databases:&lt;/p&gt;

&lt;p&gt;If you navigate to a Rails migration file, you’ll see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateExample &amp;lt; ActiveRecord::Migration[6.1]
 def change
   create_table :examples do |t|
     t.string :title
     t.string :example
     t.integer :rating
     t.timestamps
   end
 end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could ostensibly change the |t| to be |q| and the following attributes and columns to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q.string : title 
q.string : review

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

&lt;/div&gt;



&lt;p&gt;And still get your database columns built correctly, but that’s not the standard convention. &lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Rails Shortcuts for Novices</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Mon, 27 Feb 2023 03:12:10 +0000</pubDate>
      <link>https://forem.com/abflatiron/rails-shortcuts-for-novices-5g2</link>
      <guid>https://forem.com/abflatiron/rails-shortcuts-for-novices-5g2</guid>
      <description>&lt;p&gt;Here are some of my most used Rails shortcuts and their syntax cheat sheet as a Ruby on Rails novice! &lt;/p&gt;

&lt;p&gt;To start, if you return &lt;code&gt;rails&lt;/code&gt; on your command console, you’ll get a fairly extensive list of rails commands&lt;/p&gt;

&lt;p&gt;Running &lt;code&gt;rails [command] -h&lt;/code&gt; (help) will provide additional details about the specific command. &lt;/p&gt;

&lt;p&gt;This is helpful for any commands that are infrequently used. In your day to day, you’ll typically interact with a smaller subset of rails commands. &lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started:
&lt;/h2&gt;

&lt;p&gt;Creating a new Rails application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails new [your-app-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new rails application with the given name [your-app-name]. The resulting artefact is a directory with a full rails app. &lt;/p&gt;

&lt;p&gt;Starting your rails server: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  `rails server` (or) `rails s`  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This starts your rails server on localhost:3000 . Your local machine will typically automatically open a browser to the localhost:3000. &lt;/p&gt;

&lt;h2&gt;
  
  
  Rails Generator
&lt;/h2&gt;

&lt;p&gt;Rails generator is a command that allows you to create different types of rails assets from your command terminal. Rails will automatically nest the resulting asset in the correct directory (i.e. controller file in the Controller folder) and set up the class. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails generate [asset]&lt;/code&gt; (or) &lt;code&gt;rails g [asset]&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Model
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;rails g model [ModelName] column_name:datatype column_name2:datatype2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command shortcut creates a rails model. &lt;br&gt;
**Remember that model names are SINGULAR. &lt;/p&gt;

&lt;p&gt;This command also creates a corresponding migration file. The command also allows you to include the column names and column data types (if your column is a string, you do not need to specify a data type). &lt;/p&gt;

&lt;p&gt;ex. &lt;code&gt;rails g model Blog blogger_name age:integer blog_text:text&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;We would expect to see a Blog.rb model file and a create_blogs.rb migration file with the following data columns and data types: &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  blogger_name | string 
  age | integer 
  blog_text | text 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;### Generate Controller: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g controller [ControllerNames]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command shortcut creates a rails controller.&lt;/p&gt;

&lt;p&gt;**Remember that controller names are PLURAL &lt;/p&gt;
&lt;h3&gt;
  
  
  Generate Serializer
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;rails g serializer [SerializerName]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command shortcut creates a rails serializer. &lt;/p&gt;

&lt;p&gt;**Remember that serializer names are SINGULAR &lt;/p&gt;
&lt;h2&gt;
  
  
  Rails Database Commands:
&lt;/h2&gt;

&lt;p&gt;If you’ve run ‘rails’ in the command terminal, you’ll have seen rails commands that start with ‘db:’ These are database commands that you are able run for your rails backend. &lt;/p&gt;

&lt;p&gt;Here’s the full list you’ll see when you run ‘rails’:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        db:create
        db:drop
        db:environment:set
        db:fixtures:load
        db:migrate
        db:migrate:down
        db:migrate:redo
        db:migrate:status
        db:migrate:up
        db:prepare
        db:reset
        db:rollback
        db:schema:cache:clear
        db:schema:cache:dump
        db:schema:dump
        db:schema:load
        db:seed
        db:seed:replant
        db:setup
        db:structure:dump
        db:structure:load
        db:system:change
        db:version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, it's been my experience that some are more useful than others (much like the rest of the rails commands!): &lt;/p&gt;

&lt;p&gt;Some common rails database commands: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rails db:create&lt;/code&gt; Run this command FIRST and ONCE to create your database, allowing you to build your tables through migrations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rails db:migrate&lt;/code&gt; This command executes the table creation and changes in your migration files. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rails db:rollback&lt;/code&gt; This command allows you to effectively undo your last migration, going back to the prior migration state (and the changes back the schema). &lt;strong&gt;This is particularly useful to undo mistakes you might have made in your most recent migration.&lt;/strong&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rails db:seed&lt;/code&gt; If you have a seed file with sample data to "seed" your database, this command will run that seed file. Note that that file must be independently set up and your DB should already be created and your tables set up with a migration. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Console:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;rails console&lt;/code&gt; (or) &lt;code&gt;rails c&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;This command opens the rails database command console in &lt;a href="https://github.com/ruby/irb" rel="noopener noreferrer"&gt;IRB&lt;/a&gt; so you can interact directly with your ruby database. &lt;/p&gt;

&lt;p&gt;This one is really nifty for quick sanity checks on your models and checking if your objects are correctly changing on the server-side without interacting through the application. This is particularly helpful if you haven't made necessary changes to the front-end to support the server-side change logic. &lt;/p&gt;

&lt;h2&gt;
  
  
  Routes:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;rails routes&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command lists out all the RESTful routes as specified in your routes. The available routes will also be displayed in the command terminal in an organized format. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Prefix | Verb | URI Pattern | Controller#Action
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It's especially useful as reference when you need the correct URI pattern/route for an API call (and the API call verb), as well as defining the action that you'll need to write in the corresponding controller file. It can also be helpful if you're getting ramped up on a new application.  &lt;/p&gt;




&lt;p&gt;Hopefully these shortcuts aid in your coding! &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Passing Props UP ^ from Child to Parent Component</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Sun, 26 Feb 2023 02:39:12 +0000</pubDate>
      <link>https://forem.com/abflatiron/passing-props-up-from-child-to-parent-component-50nf</link>
      <guid>https://forem.com/abflatiron/passing-props-up-from-child-to-parent-component-50nf</guid>
      <description>&lt;p&gt;In my previous blog post, I covered &lt;a href="https://dev.to/abflatiron/react-props-the-bare-basics-53g4"&gt;React fundamentals&lt;/a&gt;, such as defining components, how they’re used and benefits (i.e. reusability), as well as props. If you’re new to React or need a quick refresh, I encourage you to take two minutes to review the concepts. &lt;/p&gt;

&lt;p&gt;My previous post also explained how props are passed from a Parent component to a Child  component in React. &lt;/p&gt;

&lt;p&gt;In this blog post, I’ll be writing about how props can be passed UP from a Child component to a Parent component. You might recall however, that in my previous post, I stated that props passing was unidirectional, and could only be passed from Parent to Child. &lt;/p&gt;

&lt;p&gt;Strictly speaking, this is true. In the Parent to Child relationship, we pass the prop down directly from the Parent component to the Child component, and the Child component which inherits the prop(s) is able to access the prop object, including all its object attributes (should it have any). &lt;/p&gt;

&lt;p&gt;Here’s an example of a simple prop passed from Parent → Child &lt;/p&gt;

&lt;p&gt;Ex 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Child from "./Child"

function Parent() {


   let name = "Lucky"


   return (
       &amp;lt;div&amp;gt;

           &amp;lt;h1&amp;gt; Welcome to the Parent Component, {name}! &amp;lt;/h1&amp;gt;

           &amp;lt;Child prop={name}/&amp;gt;

       &amp;lt;/div&amp;gt;
   )
}
export default Parent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Child ( {prop} ) {
   return (
       &amp;lt;div&amp;gt;
           This component is built for {prop}!
       &amp;lt;/div&amp;gt;
   )
}

export default Child;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we would expect to see this on the Application page: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ulU7ce29--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3noynq12kpozk8hcnlfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ulU7ce29--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3noynq12kpozk8hcnlfc.png" alt="Image description" width="630" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ex 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Child from "./Child"

function Parent() {


   let childObj = {
       name: "Lucky",
       color: "purple",
   }


   return (
       &amp;lt;div&amp;gt;


           &amp;lt;h1&amp;gt; Welcome to the Parent Component, {childObj.name}! &amp;lt;/h1&amp;gt;


           &amp;lt;Child prop={childObj}/&amp;gt;


       &amp;lt;/div&amp;gt;


   )
}


export default Parent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Child ( {prop} ) {


   return (
       &amp;lt;div&amp;gt;


           This component is built for {prop.name}!


           &amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;


           The color is {prop.color}.


       &amp;lt;/div&amp;gt;
   )


}


export default Child;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pI8BqcK---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/15k28izor1mexlvag74q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pI8BqcK---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/15k28izor1mexlvag74q.png" alt="Image description" width="628" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is fairly intuitive. We know that React component best practice says that each component should have a discrete role or function, and we would want to share the props with a component that has a specific use for it. We therefore may need the ability to share props from a Child component to another component, including a Parent component. &lt;/p&gt;

&lt;p&gt;You may ask, then, what situations might exist in which you would need to pass objects UP from a Child component to a Parent component? Some situations might include a Child component that makes an API call, and you want to send the returned object UP the component hierarchy or upon submission of a form that lives on a separate component to set or update State. &lt;/p&gt;

&lt;p&gt;So how do you send up Props from a Child to Parent component? Quite easily. The Prop itself is carried as a function call. A two-for-one deal, if you will. And the syntax is still the same. &lt;/p&gt;

&lt;p&gt;Let’s take for example an application where users can submit information on a form: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5oGVC6j9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ljqml9c2dq79zcmue4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5oGVC6j9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ljqml9c2dq79zcmue4u.png" alt="Image description" width="629" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our earlier example, the main welcome messagename  showed, “Lucky”. The name now shows up as “Child”. Underneath, we have a form that allows the user to change the name that appears on the page. &lt;/p&gt;

&lt;p&gt;As it is set up here, the page we are seeing now is rendered from the Parent.js file&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CnpwN1r2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e34v31vy1msfnl1s0xem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CnpwN1r2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e34v31vy1msfnl1s0xem.png" alt="Image description" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Parent component includes the useState hook, and the displayed name is set into State within the Parent component. The function that manages the state for the displayed name is called setNewName, and exists on the Parent component. You can also see that we’re making the function available to the Child component using the same syntax that we would use to pass down props. &lt;/p&gt;

&lt;p&gt;The Child component renders the form to change the displayed name. Child.js also uses the useState hook to manage the name typed into the form. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G2eJ9oak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwa5jmzl8i0rnfi48yln.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G2eJ9oak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwa5jmzl8i0rnfi48yln.png" alt="Image description" width="800" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the browser, this is what we would expect to see: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--62mKgc0l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hvdme8r29yl8wpmomkm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--62mKgc0l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hvdme8r29yl8wpmomkm.png" alt="Image description" width="629" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we’ve typed in the name “Lucky”, in order to set the welcome greeting name back to “Lucky”. &lt;/p&gt;

&lt;p&gt;Upon clicking “Submit”, our handleSubmit function calls the setNewName function, which React carries up from the Child component to the Parent component through the function Prop and sets the name State in the Parent function to Lucky. &lt;/p&gt;

&lt;p&gt;You will note that we do not have to include the “name” element in the setNewName function; the element is carried with the function through the prop chain up to the Parent component. &lt;/p&gt;

&lt;p&gt;Finally, we see the updated welcome name! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fgnrGBzv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rdbikrhximtn7jh64hr9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fgnrGBzv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rdbikrhximtn7jh64hr9.png" alt="Image description" width="628" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>props</category>
      <category>state</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Object Inheritance in Ruby #ruby #objectinheritance #superclass</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Wed, 28 Dec 2022 22:54:41 +0000</pubDate>
      <link>https://forem.com/abflatiron/object-inheritance-in-ruby-ruby-objectinheritance-superclass-5al3</link>
      <guid>https://forem.com/abflatiron/object-inheritance-in-ruby-ruby-objectinheritance-superclass-5al3</guid>
      <description>&lt;p&gt;&lt;em&gt;Tl;dr:  Ruby is an object-oriented language and allows for classes to take in the object characteristics of another class using the “&amp;lt;” symbol in the inheriting class’ Class definition file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this blogpost, I write about object inheritance in Ruby. Ruby is an object-oriented language, and one of the key features of an object-oriented language is its ability to take in the object characteristics of another class. We accomplish this by having the “subclass” inherit the characteristics of a “superclass”. Once this model is defined, then your program is able to use the class characteristics (definitions, functions, etc.) of both the sub AND super classes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are Classes in Ruby?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we jump into object inheritance, let’s quickly review the concept of a “Class”. A Class is effectively a “blueprint” for the objects you will be creating in that class. Put another way, this is where you define what type of object you are creating - so, if, as an example, you were creating individual object instances of wines (i.e. Chardonnay, Syrah), you might create a Class of “Wine” since both Chardonnay and Syrah are both a type of wine.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;However, you might also have different types of alcohol! Not only do you have wines, but you also have tequilas and whiskeys. Those are not types of wines, so you might also have another class of “Liquor” that has definitions that broadly apply to tequilas, whiskeys AND wines.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Why Object Inheritance? *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Reusability is a key part of object inheritance. It allows us as programmers to not have to duplicate code. Coming back to our example of liquor and the types of liquor, there are characteristics that wine, tequila and whiskey will all have or share: price, where it’s from, alcohol content, etc.. We wouldn’t want to copy that code for EVERY SINGLE type of alcohol! &lt;/p&gt;

&lt;p&gt;So for those reusable characteristics, we would define those in the superclass, like so:&lt;br&gt;
&lt;/p&gt;

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

   attr_accessor :price, :type_liquor, :region, :alcohol_content

 def initialize(price, type_liquor, region, alcohol_content)
   @price = price
   @type_liquor = type_liquor
   @region = region
   @alcohol_content =alcohol_content
 end

  def alcohol
   "Careful, this will get you buzzed."
 end


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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Superclass and Subclass&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;In the hierarchy of object inheritance, we have what are called “Superclass” and “Subclass”. The Superclass is the class from which the Subclass “inherits” the object characteristics. In our example, “Liquor” would be a Superclass, and the type of liquor would be a “Subclass”.&lt;/p&gt;

&lt;p&gt;Syntax for Object Inheritance&lt;/p&gt;

&lt;p&gt;We use the inequality symbol &lt;code&gt;&amp;lt;&lt;/code&gt; (or shovel) for the subclass to inherit the superclass. We can also define characteristics, methods, specific to the Wine class in the Wine file as well. &lt;/p&gt;

&lt;p&gt;Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Wine &amp;lt; Liquor

   def how_to_drink 
       "To drink the wine, take a small sip and swirl the wine in your mouth"
   end

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

&lt;/div&gt;



&lt;p&gt;And it’s as simple as that! Now, all the characteristics we defined in our Liquor class are available to our Wine class. &lt;/p&gt;

&lt;p&gt;Now let’s try it out in IRB!&lt;/p&gt;

&lt;p&gt;First, let’s make sure that Wine has inherited the superclass of Liquor. You can use a method called #superclass. When appended to a class, it will tell you that class’ superclass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.7.4 :001 &amp;gt; require_relative 'liquor'
 =&amp;gt; true 
2.7.4 :002 &amp;gt; require_relative 'wine'
 =&amp;gt; true 
2.7.4 :003 &amp;gt; Wine.superclass
 =&amp;gt; Liquor 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s initialize an instance of Wine, called “chardonnay”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.7.4 :004 &amp;gt; chardonnay = Wine.new("$10", "wine", "California", "14%")
 =&amp;gt; #&amp;lt;Wine:0x00007fc25d95a5c0 @price="$10", @type_liquor="wine", @regio... 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;*Note how all the parameters we are giving to chardonnay through the Wine class were actually defined up in the Liquor class. Recall also that the Wine class has no object parameters defined. Wine has inherited all the characteristics of Liquor, and we’re able to create the object with parameters defined in the superclass.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Coming back to our method #superclass - if we were encountering the object “chardonnay” and needed to learn more about its class hierarchy, we could string #class and #superclass to traverse the class hierarchy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.7.4 :009 &amp;gt; chardonnay.class
 =&amp;gt; Wine 
2.7.4 :010 &amp;gt; chardonnay.class.superclass
 =&amp;gt; Liquor 

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

&lt;/div&gt;



&lt;p&gt;Moving along, recall we defined a method, #how_to_drink,  in our Wine class. Let’s see what that method says about how to drink our chardonnay:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.7.4 :006 &amp;gt; chardonnay.how_to_drink
 =&amp;gt; "To drink the wine, take a small sip and swirl the wine in your mouth" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Solid advice, but more importantly, our class method works!&lt;/p&gt;

&lt;p&gt;Finally, let’s call the method #alcohol that we defined in our superclass, Liquor, on our object chardonnay:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.7.4 :005 &amp;gt; chardonnay.alcohol
 =&amp;gt; "Careful, this will get you buzzed." 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Success! &lt;/p&gt;

&lt;p&gt;&lt;em&gt;[Aside: you might be wondering what happens when both the superclass and subclass have a method with the same name. In this situation, the subclass’ method will overwrite the inherited method. So, if Liquor.rb also had &lt;code&gt;#how_to_drink method&lt;/code&gt;, the method &lt;code&gt;#how_to_drink&lt;/code&gt; in Wine.rb would overwrite Liquor’s. ]&lt;/em&gt;&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>React Props: The Bare Basics</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Sun, 24 Jul 2022 23:49:23 +0000</pubDate>
      <link>https://forem.com/abflatiron/react-props-the-bare-basics-53g4</link>
      <guid>https://forem.com/abflatiron/react-props-the-bare-basics-53g4</guid>
      <description>&lt;h2&gt;
  
  
  React Components:
&lt;/h2&gt;

&lt;p&gt;One of the key and notable features of React is components. React allows developers to build reusable components of an application that can then be rendered together. In practical terms, components allow a building block style of building applications: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Components, as a best practice, are built with discrete functionality and purpose&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Components can be reused, either in other parts of the code, or for different applications altogether&lt;br&gt;
If implemented well, discrete functionalities for components allows for easier understanding of the individual parts of the application and management of the code base &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While the components may be rendered together, components must also be able to share information and pass values to one another. This is a job for Props. &lt;/p&gt;

&lt;h2&gt;
  
  
  Props:
&lt;/h2&gt;

&lt;p&gt;Props play an important role in passing values between the components. &lt;/p&gt;

&lt;p&gt;While React components are effectively separate pieces of functional code, when they are used in combination to support an application, those components must be able to share values (or arguments) with each other! Props allow for this transmission of values from one component to another. However, it is important to remember that information through Props allows for passing values from a parent component down to a child component. That is to say, Props sharing is unidirectional. Props can be passed from child to parent, but that is accomplished through function calls, and the function arguments are what the parent component receives. That is a subject for another blog post, and this blog post spotlights parent to child props passing. &lt;/p&gt;

&lt;h2&gt;
  
  
  Props Overview:
&lt;/h2&gt;

&lt;p&gt;Some key syntactical concepts to grok:&lt;/p&gt;

&lt;p&gt;Props are passed to components via HTML attributes, so we write the props we want to send down to child components in the same syntax as an HTML attribute. &lt;/p&gt;

&lt;p&gt;Props values can be an object, integer, string, boolean, array and even a function! &lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;

&lt;p&gt;For the purposes of illustration, let's use the following example: We have an application whose parent component needs to pass down props, &lt;em&gt;a name as string object&lt;/em&gt;, to a child component.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function ParentComponent() {&lt;br&gt;
   return (&lt;br&gt;
       &amp;lt;ChildComp name="Jake"/&amp;gt; //the prop called "name" is written as we would an attribute for an HTML tag and given the value "Jake"&lt;br&gt;
   )&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now we can access the props in the Child component:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function ChildComponent(props) {&lt;br&gt;
   //now we can access the prop!&lt;br&gt;
   return(&lt;br&gt;
       &amp;lt;div&amp;gt;&lt;br&gt;
           "Hi {props.name}!"  {/* Note how to access the 'Props' is accessed as you would a key-value pair!  */}&lt;br&gt;
       &amp;lt;/div&amp;gt;&lt;br&gt;
       );&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing multiple props
&lt;/h2&gt;

&lt;p&gt;But what if we have multiple props? You can use the same convention of writing props (as you would write HTML attributes) as you saw in the previous example for each additional prop you want to specify. To access those props, just as you would access an object with multiple key-value pairs, you would access the props using dot notation in the child component.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function ParentComp() {&lt;br&gt;
   return (&lt;br&gt;
       &amp;lt;ChildComp name="Jake" hometown="Boise"/&amp;gt;&lt;br&gt;
   )&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;function ChildComp(props) {&lt;br&gt;
   return(&lt;br&gt;
       &amp;lt;div&amp;gt;&lt;br&gt;
           "Hi {props.name}!"  {/* To access the 'name' we use dot notation to access the name value */}&lt;br&gt;
           "Are you from {props.hometown}?" {/* the same format is used to access the 'hometown' value */}&lt;br&gt;
       &amp;lt;/div&amp;gt;&lt;br&gt;
       );&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Prop Destructuring:
&lt;/h2&gt;

&lt;p&gt;In the previous examples, we passed simple values (as strings) to our child component using props. In real world applications, this may or may not be the case. You could have a child component that needs to take in simple constant value. &lt;/p&gt;

&lt;p&gt;However, React’s usefulness and power comes in the ability for parent components (by way of the developer, of course) to pass down just the information that a child component needs. &lt;/p&gt;

&lt;p&gt;Let’s take for example a application that displays the images of paintings, and an image’s complete object record looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
   "objectID": 436532,&lt;br&gt;
   "isHighlight": true,&lt;br&gt;
   "primaryImage": "https://images.metmuseum.org/CRDImages/ep/original/DT1502_cropped2.jpg",&lt;br&gt;
   "primaryImageSmall": "https://images.metmuseum.org/CRDImages/ep/web-large/DT1502_cropped2.jpg",&lt;br&gt;
   "department": "European Paintings",&lt;br&gt;
   "objectName": "Painting",&lt;br&gt;
   "title": "Self-Portrait with a Straw Hat (obverse: The Potato Peeler)",&lt;br&gt;
   "artistDisplayName": "Vincent van Gogh",&lt;br&gt;
   "artistDisplayBio": "Dutch, Zundert 1853–1890 Auvers-sur-Oise",&lt;br&gt;
   "artistNationality": "Dutch",&lt;br&gt;
   "artistBeginDate": "1853",&lt;br&gt;
   "artistEndDate": "1890",&lt;br&gt;
   "objectDate": "1887"&lt;br&gt;
   "medium": "Oil on canvas",&lt;br&gt;
   "dimensions": "16 x 12 1/2 in. (40.6 x 31.8 cm)",&lt;br&gt;
 }&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;While the parent component may contain the entirety of the painting’s object data as shown above, a child component responsible for rendering the image and the image’s title may not need all of the object data. &lt;/p&gt;

&lt;p&gt;Cue props destructuring. &lt;/p&gt;

&lt;p&gt;To render the image onto the DOM, the child prop may only need the title of the painting and the image url. Instead of passing the entire object value down to the child component, you can destructure your prop and send only the information the child component needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ParentComp() {
   return (
       &amp;lt;ChildComp imageUrl={paintingObj.primaryImage}  imageTitle={prop.title}/&amp;gt;
   )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ChildComp(imageUrl, imageTitle) {
   //compare to the previous example, where we pass down "Props"
   //here we have explicitly called out the prop key from the parent component

   return(
       &amp;lt;div&amp;gt;
           &amp;lt;h1&amp;gt;{imageTitle}&amp;lt;/h1&amp;gt;
           &amp;lt;img class="img" src={imgObj.primaryImage}/&amp;gt;
       &amp;lt;/div&amp;gt;
   )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we’d expect to see this: &lt;/p&gt;

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

&lt;p&gt;(You can also read more about Props &lt;a href="https://www.w3schools.com/react/react_props.asp" rel="noopener noreferrer"&gt;here&lt;/a&gt; )&lt;/p&gt;

&lt;p&gt;Happy Coding! &lt;/p&gt;

</description>
      <category>react</category>
      <category>props</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My First Post! &amp;&amp; href in Javascript</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Tue, 05 Apr 2022 02:31:21 +0000</pubDate>
      <link>https://forem.com/abflatiron/my-first-post-href-in-javascript-409j</link>
      <guid>https://forem.com/abflatiron/my-first-post-href-in-javascript-409j</guid>
      <description>&lt;p&gt;Thanks for checking out my first blog post on dev.to! In my inaugural post, I’ll be discussing how to use the &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; HTML attribute with javascript: what &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; is, and why it’s used, how to use it in the context of js, and my experience working with &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt;. Before I jump into the technical details, I’ll be sharing a little bit about my background, and the project that led me to write about href. &lt;/p&gt;

&lt;h2&gt;
  
  
  [about me]
&lt;/h2&gt;

&lt;p&gt;Before we jump into the technical details about our main topic, a little more about me. I’ve spent the last decade in tech, having worked for several start-ups in software in various client-facing roles. I didn’t originally set out to work in tech, having read philosophy (specifically some arcane political philosophy at that) while in university, and rather ‘fell into it’. I now work as a technical program manager in big tech.&lt;/p&gt;

&lt;p&gt;I’ve been extraordinarily lucky to have had many brilliant technical mentors over the years. They taught me many software fundamentals and many technical management (re: Scrum, Kanban) theories. Over time, I picked up enough through mentors, on-the-job learning and self-study to be effective in my field, but I always felt at a disadvantage (re: imposter syndrome) for not receiving any formal software engineering training. &lt;/p&gt;

&lt;p&gt;The pandemic provides some dedicated time at home for me to learn new things, so I decided to sign up for a coding bootcamp to round out my technical skills. This blog, and the javascript project I coded using &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; are  part of my program curriculum.&lt;/p&gt;

&lt;h2&gt;
  
  
  [info about my project]
&lt;/h2&gt;

&lt;p&gt;The capstone for the first phase of my program is a simple web app. I decided to use a URL shortening API to code a single-page web app that allows users to shorten URLs, and have the links show up on the page. This project necessitated an understanding of and leveraging the &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; attribute. This blog post shares what I learned about this topic through my project. &lt;/p&gt;

&lt;p&gt;You can access the web app and source code through my &lt;a href="https://github.com/austinbaik/Austin-phase-1-js-project/tree/main"&gt;github:&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  [What is &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; and what does it do?]
&lt;/h2&gt;

&lt;p&gt;Strictly speaking, the &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; is an HTML tag, and the ‘href’ is the tag attribute. Href comes from “&lt;strong&gt;H&lt;/strong&gt;ypertext &lt;strong&gt;REF&lt;/strong&gt;erence”.&lt;/p&gt;

&lt;p&gt;Together (and &lt;em&gt;always&lt;/em&gt; together) &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; href renders a clickable link to a local file or url. &lt;br&gt;
"anchor text. Which is the clickable text&lt;/p&gt;

&lt;p&gt;Remember: You must use the href attribute with an &lt;code&gt;&amp;lt;a&amp;gt; &amp;lt;/a&amp;gt;&lt;/code&gt;  tag. &lt;/p&gt;

&lt;p&gt;Here’s for the &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; is constructed: Link , Target, &amp;amp; Title &lt;br&gt;
Link is the url or file path. &lt;br&gt;
Target is how you want the linked document to open (new window, same frame, etc. - you can read more on this &lt;a href="https://www.w3schools.com/tags/att_a_target.asp"&gt;here&lt;/a&gt;.&lt;br&gt;
Title is what you want the link to show up as on the webpage&lt;/p&gt;

&lt;p&gt;How to use &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; in Javascript: &lt;/p&gt;

&lt;p&gt;So, when might you want to manipulate document links through your javascript instead of coding the links into the html - after all, &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; is an html tag and attribute? &lt;/p&gt;

&lt;p&gt;There were two requirements for my URL shortener app 1) take a long form url and return a short link &amp;amp; 2) add both the original and short links to the web page as clickable hyperlinks. &lt;/p&gt;

&lt;p&gt;We therefore need a mechanism to update the web page with the new content. To accomplish this, I used &lt;code&gt;&amp;lt;a&amp;gt; href&lt;/code&gt; in my javascript to dynamically update the web page. &lt;/p&gt;

&lt;p&gt;My approach to getting the URLs added to the DOM was to create an &lt;/p&gt;
&lt;li&gt; element, set as a variable ‘let’, and then set the innerHTML of let as one big template literals block (the stuff between &lt;code&gt;the stuff&lt;/code&gt; ). I then used string interpolation to place the url (as a locally scoped variable  ${urlHere)   ) as the href link. 

&lt;p&gt;You’ll note that the Target is set as “_blank”, which opens the link in a new window when clicked on the webpage. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;let card = document.createElement('li')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;card.className = 'card'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;card.innerHTML =&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;&amp;lt;a href= ${orgLink} target = "_blank"&amp;gt; ${orgLink} &amp;lt;/a&amp;gt;&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;&amp;lt;br/&amp;gt;&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;&amp;lt;a href= ${shortLink} target = "_blank"&amp;gt; "Short Link"&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;&amp;lt;div class ="buttons"&amp;gt;&lt;/code&gt;&lt;br&gt;
       &lt;code&gt;&amp;lt;button id="close"&amp;gt; X &amp;lt;/button&amp;gt;&lt;/code&gt;&lt;br&gt;
   &lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;`&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Alternatively, I could have had my javascript function append the attribute and the link title step by step. However, I opted against this method as I needed to add more than one URL, together, to show up on the web page, and this approach would result in a lot more lines of code.&lt;/p&gt;

&lt;p&gt;Example: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;function example() {&lt;br&gt;
   NewUrl = document.createElement('a');&lt;br&gt;
   let url = document.createTextNode("Url Link Title");&lt;br&gt;
   a.appendChild(url);&lt;br&gt;
   a.title = "This is Link";&lt;br&gt;
   a.href = "https://www.SuperDuperLongUrl.com";&lt;br&gt;
   document.body.appendChild(a)&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy Coding! &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Sources: &lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/tags/att_a_href.asp"&gt;https://www.w3schools.com/tags/att_a_href.asp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/the-a-href-attribute-explained/"&gt;https://www.freecodecamp.org/news/the-a-href-attribute-explained/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a"&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.pcmag.com/encyclopedia/term/href#:%7E:text=The%20HREF%20is%20an%20attribute,called%20the%20%22anchor%20text.%22"&gt;https://www.pcmag.com/encyclopedia/term/href#:~:text=The%20HREF%20is%20an%20attribute,called%20the%20%22anchor%20text.%22&lt;/a&gt;&lt;/p&gt;


&lt;/li&gt;

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