<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bianca Charlotin</title>
    <description>The latest articles on DEV Community by Bianca Charlotin (@bcharlotin1).</description>
    <link>https://dev.to/bcharlotin1</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%2F535793%2F269456aa-3d13-4c2d-8e20-7b9d472e73a7.jpeg</url>
      <title>DEV Community: Bianca Charlotin</title>
      <link>https://dev.to/bcharlotin1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bcharlotin1"/>
    <language>en</language>
    <item>
      <title>useParams and Dynamic Routes </title>
      <dc:creator>Bianca Charlotin</dc:creator>
      <pubDate>Thu, 09 Dec 2021 23:17:52 +0000</pubDate>
      <link>https://dev.to/bcharlotin1/useparams-and-dynamic-routes-52k1</link>
      <guid>https://dev.to/bcharlotin1/useparams-and-dynamic-routes-52k1</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;This post will discuss how to use &lt;code&gt;useParams&lt;/code&gt; to create dynamic routes with your React application.  While working on my first React application, I had a complex time understanding &lt;code&gt;useParams&lt;/code&gt; and its use,  even with my trusty friend Google. So I'm writing this blog post to help the next person who goes down this rabbit hole. &lt;/p&gt;

&lt;h3&gt;
  
  
  What is &lt;code&gt;useParams&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;In the most basic definition &lt;code&gt;useParams&lt;/code&gt; is a React Hook that allows you to extract parameters from the URL in one line. &lt;/p&gt;




&lt;h2&gt;
  
  
  How To Use &lt;code&gt;useParams&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;I will be using examples from my react App. to demonstrate how I used the hook. So let me clue you in on it:&lt;/p&gt;

&lt;p&gt;I built a task manager App that has projects,  and those projects have tasks. &lt;/p&gt;

&lt;p&gt;I had a &lt;code&gt;"/project"&lt;/code&gt; route with the child component of Tasks.  I wanted each of these projects to render its own tasks using dynamic URLs. Meaning, I wanted Project 1's Tasks to display a URL that looks like this &lt;code&gt;"/projects/1/tasks"&lt;/code&gt; without having to do so explicitly.&lt;/p&gt;




&lt;h3&gt;
  
  
  App.js File Declaring my Routes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PageLayout&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/layout/PageLayout&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;projects/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PageLayout&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;   &lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Routes&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;



&lt;p&gt;In the code above, I have declared my routes &lt;code&gt;"projects/*"&lt;/code&gt;, which will render the &lt;code&gt;&amp;lt;PageLayout /&amp;gt;&lt;/code&gt;component.  Looking at the path carefully, you see an  &lt;code&gt;/*&lt;/code&gt; at the end.  &lt;strong&gt;The asterisk at the end means that all routes that look like &lt;code&gt;projects/&lt;/code&gt; will be handled by the PageLayout component&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  PageLayout Component: Setting Up Dynamic Routes
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;PageLayout /&amp;gt;&lt;/code&gt; display is where I have the layout template used for all other routes declared and components imported, which means this component is the template for my other pages.  &lt;/p&gt;

&lt;p&gt;PageLayout Component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ProjectDisplay&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../projects/ProjectDisplay&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ProjectInput&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../projects/ProjectInput&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ProjectUpdate&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../projects/ProjectUpdate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;TaskDisplay&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../tasks/TaskDisplay&lt;/span&gt;&lt;span class="dl"&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;PageLayout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProjectDisplay&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;new&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProjectInput&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;:id/edit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProjectUpdate&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;:id/tasks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;TaskDisplay&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;       &lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Routes&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Let look at each route &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Route path="/" element={&amp;lt;ProjectDisplay /&amp;gt;} /&amp;gt;&lt;/code&gt;  . I have declared this URL structure: "projects/". renders all my projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Route path="new" element={&amp;lt;ProjectInput /&amp;gt;} /&amp;gt;&lt;/code&gt; I have declared this URL structure: "projects/new", renders my project form for new project creation.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dynamic Routes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Route path=":id/edit" element={&amp;lt;ProjectUpdate /&amp;gt;} /&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Route path=":id/tasks" element={&amp;lt;TaskDisplay /&amp;gt;} /&amp;gt;&lt;/code&gt;&lt;br&gt;
The colon indicates to React that this will be a dynamic route, I put "id" after because I decided that is what I'm passing in, but it can be called anything, ex: &lt;code&gt;:name&lt;/code&gt;, &lt;code&gt;:project_id&lt;/code&gt;. Just make sure you're consistent. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Where are Dynamic Routes Getting Their Parameters?
&lt;/h3&gt;

&lt;p&gt;Naturally, where I'm displaying all my projects is the most natural choice for me. I linked all project names to their corresponding tasks and sent the parameters through those links.   &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%2Fgp11si5fqnxqlt66zo4q.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%2Fgp11si5fqnxqlt66zo4q.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is my &lt;code&gt;&amp;lt;ProjectDisplay /&amp;gt;&lt;/code&gt; code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;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;ProjectDisplay&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;projects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`/projects/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/tasks`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&amp;gt;&lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;
 &lt;span class="p"&gt;})}&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Above I am iterating over a projects array in this code to display all projects. I have established a link. Looking at the links pathway &lt;code&gt;/projects/${p.id}/tasks&lt;/code&gt;  you see that for  &lt;code&gt;&amp;lt;Route path=":id/tasks" element={&amp;lt;TaskDisplay /&amp;gt;} /&amp;gt;&lt;/code&gt; that we declared earlier we are passing in the full URL,  but instead of the &lt;code&gt;:id&lt;/code&gt; we are passing in the projects id. Passing in this information is how your URLs go from: &lt;code&gt;/projects/:id/tasks&lt;/code&gt;  to &lt;code&gt;/projects/1/tasks&lt;/code&gt; &lt;/p&gt;




&lt;h3&gt;
  
  
  Extracting The Parameters Sent!
&lt;/h3&gt;

&lt;p&gt;I'm going to be calling the hook &lt;code&gt;useParams&lt;/code&gt; on whichever component I have established the dynamic route for. In the example above, I linked my project page to go to the task page/&lt;code&gt;&amp;lt;TaskDisplay /&amp;gt;&lt;/code&gt; component. &lt;/p&gt;

&lt;p&gt;TaskDisplay Component:&lt;br&gt;
The reason I sent the &lt;code&gt;id&lt;/code&gt; of my projects is because each project has a different set of tasks. To find and display these tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I need to know what project URL im on,  and find that projects task
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useParams&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;TaskDisplay&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useParams&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;useParamsProjectId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&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;allTasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&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;projectTasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nx"&gt;allTasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;useParamsProjectId&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;)&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;const { id } = useParams()&lt;/code&gt;:  Declared a variable using the  destructured value of &lt;code&gt;useParmas&lt;/code&gt;. &lt;code&gt;{ id }&lt;/code&gt; is the name I gave  my dynamic route `.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;const useParamsProjectId = parseInt(id)&lt;/code&gt;:  Declared a variable which returns  &lt;code&gt;id&lt;/code&gt; that has been converted into an integer to use to compare later. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;const allTasks = useSelector(state =&amp;gt; state.tasks)&lt;/code&gt;: Here I am Grabbing all tasks from &lt;code&gt;state&lt;/code&gt; (independent of the project) and setting it equal to a variable called &lt;code&gt;alltasks&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;const projectTasks =  allTasks.filter((task) =&amp;gt; (task.project_id === useParamsProjectId))&lt;/code&gt;: I'm using the method &lt;code&gt;filter()&lt;/code&gt; to return a new array with all tasks that's  &lt;code&gt;project_id&lt;/code&gt;  matches the &lt;code&gt;useParams id&lt;/code&gt; aka &lt;code&gt;useParamsProjectId&lt;/code&gt; and setting it equal to a variable called projectTasks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There you have it &lt;code&gt;useParams&lt;/code&gt; in full circle !&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React Hooks and Fetch</title>
      <dc:creator>Bianca Charlotin</dc:creator>
      <pubDate>Mon, 06 Dec 2021 15:51:25 +0000</pubDate>
      <link>https://dev.to/bcharlotin1/react-hooks-and-fetch-50dn</link>
      <guid>https://dev.to/bcharlotin1/react-hooks-and-fetch-50dn</guid>
      <description>&lt;p&gt;This blog will be detailing how to use React Hooks with Fetch to get data.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Note that all React packages need to be 16.8.0 or higher to enable Hooks. Hooks won't work if you forget to update".&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend
&lt;/h2&gt;

&lt;p&gt;Let's first look at the database I used for this demonstration. I used a rails API, but we won't be getting any deeper than this; all you need to know are the attributes that are set up in the table to understand the examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;create_table&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;projects&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;force&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;cascade&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;datetime&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;created_at&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;precision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;datetime&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;updated_at&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;precision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="nx"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet shows a table called "Projects" that has 2 attributes "Title" and "Description". &lt;/p&gt;




&lt;h2&gt;
  
  
  Frontend
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Project Display Component
&lt;/h4&gt;

&lt;p&gt;Displayed is the "project display functional component". The goal. heere. is to  have this component fetch all the projects from my backend so that it can be displayed. &lt;/p&gt;

&lt;p&gt;Let's first take a look at the "imports"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fetchProjects&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./projectAction&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useDispatch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;useEfect&lt;/code&gt; is similar to &lt;code&gt;componentDidMount()&lt;/code&gt; which runs additional code before React has updated the DOM. This is important because we want to get our data before the page loads. No data means no projects can be displayed on the DOM. How do we get our data? Yes, Fetch!&lt;br&gt;
This is where the fetch request is happening. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;fetchProjects&lt;/code&gt; is a functional component I created just to handle get request. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;useDispatch&lt;/code&gt; is similar to &lt;code&gt;connect&lt;/code&gt;. &lt;code&gt;useDispatch&lt;/code&gt; is React Hooks' way to trigger a state change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;useSelector&lt;/code&gt; is similar to how we would call "this.props.projects" to get data from the redux store; now we have &lt;code&gt;useSelector&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Putting It All Together
&lt;/h3&gt;

&lt;h5&gt;
  
  
  Project Display Component Functions and Declarations
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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="nx"&gt;ProjectDisplay&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;projects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projects&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;dispatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useDispatch&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fetchProjects&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;const&lt;/code&gt; declaration of "projects" is the return value of &lt;code&gt;useSelector&lt;/code&gt;. How you set up your reducer(s) and store reflects how you call your state. Typically if  you only passed in 1 reducer component in my redux store, you would just use &lt;code&gt;const projects =useSelector(state =&amp;gt; state)&lt;/code&gt;, but I passed in a &lt;code&gt;combineReducer&lt;/code&gt;,  which like it says, combines all the different reducer components,  so you have to specify which one you want. How the &lt;code&gt;Store&lt;/code&gt; looks like ...
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;applyMiddleware&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;combineReducers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;thunk&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;redux-thunk&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;userReducer&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;./reducers/userReducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;projecReducer&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;./reducers/projectReducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;taskReducer&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;./reducers/taskReducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;


&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;rootReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;combineReducers&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;userReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;projects&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;projecReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;taskReducer&lt;/span&gt;  &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rootReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;applyMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thunk&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;2.&lt;code&gt;const&lt;/code&gt; declaration of "dispatch" gives us access to the usDispatch function by just calling Dispatch&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;useEffect&lt;/code&gt; takes in 2 arguments. The first argument takes in a function.  In this example, we created a call-back function with &lt;code&gt;dispatch&lt;/code&gt; to trigger a change in&lt;code&gt;state&lt;/code&gt;. Then in our function dispatch we call on our &lt;code&gt;fetch&lt;/code&gt; function (fetchProject). The second argument in &lt;code&gt;useEffect&lt;/code&gt; takes in an array of dependencies. In this example, we have none, so we left the array empty.&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Fetch Function (fetchProject)
&lt;/h5&gt;

&lt;p&gt;You should already be familiar with how to write a &lt;code&gt;fetch&lt;/code&gt; function, so I will only be getting into how it changes our &lt;code&gt;state&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fetchProjects&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:3000/projects&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;projects&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 

            &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SET_PROJECTS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;projects&lt;/span&gt;&lt;span class="p"&gt;})})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;What is fetch doing? Fetch is  going to the url provided, in this case the route of my backend and 'GET'/getting all the projects. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The new addition to this fetch request is &lt;code&gt;dispatch({type:SET_PROJECTS, payload: projects}&lt;/code&gt;. In the second &lt;code&gt;promise&lt;/code&gt; of our function. We call &lt;code&gt;dispatch&lt;/code&gt; to change the state, which we still need to do within the fetch request. &lt;code&gt;dispatch&lt;/code&gt; takes in an &lt;code&gt;action&lt;/code&gt;, an object that describes what happened (&lt;code&gt;{type:SET_PROJECTS, payload: projects}&lt;/code&gt;). &lt;code&gt;type&lt;/code&gt; is a string used to match  our &lt;code&gt;case&lt;/code&gt; in the &lt;code&gt;switch&lt;/code&gt; statement (located in the reducer which changes our store's &lt;code&gt;state&lt;/code&gt;). &lt;code&gt;payload&lt;/code&gt; in this example is the data retrieved.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Change state with Reducers
&lt;/h5&gt;

&lt;p&gt;Remember that we are passing in reducers to our redux store,  so to change our &lt;code&gt;state&lt;/code&gt; inside of our store, we must modify the information in our reducers. After the fetch request, the second dispatch accesses the reducer. &lt;/p&gt;

&lt;p&gt;This is the Project Reducer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;projectReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SET_PROJECTS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The project reducer takes in 2 arguments. 1. the state,  which is being defaulted to an empty array,  and 2.  action, which is what refers to the object that was sent through dispatch (&lt;code&gt;dispatch({type:SET_PROJECTS, payload: projects}&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.With &lt;code&gt;switch&lt;/code&gt; the value of the expression (action.type) is compared with the values of each case. in this example, we used action.type,  which renders out to be "SET_PROJECTS" because it is what was passed through in our &lt;code&gt;dispatch&lt;/code&gt;. In the case statement, we are returning the state. By calling action.payload  the state is snow equal to the data we got from our fetch,  which is an array of  Project objects .&lt;/p&gt;

&lt;h5&gt;
  
  
  Back to Project Display Component to render
&lt;/h5&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;projects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projects&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that our &lt;code&gt;state&lt;/code&gt; is an array of project objects We can render them in our DOM. remember our  &lt;code&gt;useSelector&lt;/code&gt; function declared earlier in the project component? We can use the const project like this ...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Projects&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

                &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;projects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;


                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;completion_rate&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;})}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Delete&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                &lt;span class="p"&gt;)})}&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;            &lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see we are mapping through projects and displaying each project in an unordered list on the DOM. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Javascript's "This" Keyword Class Context </title>
      <dc:creator>Bianca Charlotin</dc:creator>
      <pubDate>Tue, 05 Oct 2021 22:00:37 +0000</pubDate>
      <link>https://dev.to/bcharlotin1/javascript-s-this-keyword-class-context-3e3m</link>
      <guid>https://dev.to/bcharlotin1/javascript-s-this-keyword-class-context-3e3m</guid>
      <description>&lt;p&gt;While building my first application with a Rails API I built, and a Javascript frontend, I ran into a lot of trouble figuring out &lt;code&gt;This&lt;/code&gt;. In this blog post, I will break down &lt;code&gt;This&lt;/code&gt; from a Class context with examples from my project, and show you how to always find out what &lt;code&gt;This&lt;/code&gt; is, using Debugger.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is&lt;code&gt;This&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;This&lt;/code&gt;is almost like the Ruby Keyword &lt;code&gt;Self&lt;/code&gt;, but unlike &lt;code&gt;Self&lt;/code&gt;, &lt;code&gt;This&lt;/code&gt; can be a lot more fickle. Just like in writing context is import. "this"can refer to many different things based of the sentence written. In Javascript &lt;code&gt;This&lt;/code&gt; is defined based on where it is being used. &lt;/p&gt;

&lt;h5&gt;
  
  
  Code along with me:
&lt;/h5&gt;

&lt;p&gt;Create an index.html file, and an index.js file, and add the js file to the HTML file. Then place a &lt;code&gt;debugger&lt;/code&gt; in an empty javascript file, open your index.html file in your browser and the inspect tool. You should automatically hit your debugger. Then write. &lt;code&gt;This&lt;/code&gt; in your console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8dzNiJDa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8ihpc31a35e7e38whnd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8dzNiJDa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8ihpc31a35e7e38whnd.png" alt="Debugger in js file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NDK930Os--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2u68rlwpgs8183rh3osb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NDK930Os--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2u68rlwpgs8183rh3osb.png" alt="console in the inspect tool"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;This&lt;/code&gt; is defined as the window object represents an open window in a browser. *&lt;em&gt;Important:  &lt;code&gt;This&lt;/code&gt; always references an object *&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Class Context:
&lt;/h3&gt;

&lt;p&gt;It's important to remember that a class is an object, and from what we have already learned about &lt;code&gt;This,&lt;/code&gt;This` within a Class will point to the Class object.&lt;/p&gt;

&lt;p&gt;This is a Pets Class I created within it is a class function called constructor *(if you are familiar with ruby constructor is like initializer) &lt;/p&gt;

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

&lt;p&gt;This is the value of &lt;code&gt;This&lt;/code&gt; inside a constructor (using console to type in &lt;code&gt;This&lt;/code&gt; to get the value). As you can see it's referring to a Pets object, which is an instance of the Pets Class(currently, has no attributes since we didn't pass any in). &lt;/p&gt;

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

&lt;h4&gt;
  
  
  What About Static Class Functions?
&lt;/h4&gt;

&lt;p&gt;Here are where things can change. Unlike regular methods within a Class, static methods are not called on an instance of a Class, but on the Class itself ex: Pets.create()&lt;/p&gt;

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

&lt;p&gt;As you can see in the image below, &lt;code&gt;This&lt;/code&gt; is now referring to the Class (Not an Instance of the class)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KeYd-1Qv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xn8lgmxd3dl8me1jf3e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KeYd-1Qv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xn8lgmxd3dl8me1jf3e.png" alt="static this result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;**Important: It is important to note that &lt;code&gt;This&lt;/code&gt; can also change based on the way you write your functions. If we were to use arrow functions on our static method &lt;code&gt;This&lt;/code&gt; would return undefined &lt;/p&gt;

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

&lt;p&gt;This is because Arrow functions inherit their &lt;code&gt;This&lt;/code&gt; from the outer scope rather than their &lt;code&gt;This&lt;/code&gt; depending on their calling context. So in the example &lt;code&gt;This&lt;/code&gt; is trying to refer to the static method of create() which is not an Instance of the class object. &lt;/p&gt;

&lt;p&gt;Static Method:- there is no need to create an object in order to use static method. means "instance" or object creation doesn't any sense with "static" as per Java rule  &lt;/p&gt;

&lt;h3&gt;
  
  
  Tips and Tricks to Find &lt;code&gt;This&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;debugger&lt;/code&gt;,&lt;code&gt;debugger&lt;/code&gt;, &lt;code&gt;debugger&lt;/code&gt;!  You cna use debugger jsut about anywhere in you javascript code, this will alwaa you to use the browser console to  check out what &lt;code&gt;This&lt;/code&gt; is. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example of how to find this for a Javascript event:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;This is more of an advanced example but was surely helpful in my project.&lt;/p&gt;

&lt;p&gt;playGameButton is a DOM element I set in my index.js  for a button I have on my Html file.  I have an event listener for a "click", When the event occurs, an event object is passed to the function, and that object is now. what &lt;code&gt;This&lt;/code&gt; is equal to. An EventListener is an object that handles an event.  &lt;/p&gt;

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

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

&lt;p&gt;** For more help please refer to this : &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>My First Rails App</title>
      <dc:creator>Bianca Charlotin</dc:creator>
      <pubDate>Sat, 07 Aug 2021 18:20:47 +0000</pubDate>
      <link>https://dev.to/bcharlotin1/my-first-rails-app-1d23</link>
      <guid>https://dev.to/bcharlotin1/my-first-rails-app-1d23</guid>
      <description>&lt;p&gt;This blog post will be discussing the process of completing my third flatiron coding project. It will go into detail on the project I created and the difficulties I encountered.&lt;/p&gt;

&lt;p&gt;This project focused on using Rails (a Ruby framework) and developing a web application. Since my last project was more social media-focused, I wanted to create something game-related this time around. So I developed a Game review site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CcS_A4gI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfwb34qo63y99tpwhwpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CcS_A4gI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfwb34qo63y99tpwhwpq.png" alt="Screen Shot 2021-08-07 at 1.36.20 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just like in Sinatra we were introduced to ULR's, GET and POST requests, etc. However, this time around, since Rails is fitted for a larger web application we got cool new features like its generator property that pre-populated your rails app with models, migrations, views, and helpers needed for the project, my favorite was "rails g resource ...".&lt;/p&gt;

&lt;p&gt;This project consisted of building an app that had Rails associations, which is a connection between two Active Record models. Allowing users to signup, log in through the app, or through a third-party signup/login (OmniAuth), and the ability to log out. Some methods required were the use of Scope and helper methods within the app. I will be going into each of these requirements below.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rails associations: This part was what I wrote out first to 
make sure I had models that could create the associations 
needed for this project
   -Include at least one has_many relationship 
   -Include at least one belongs_to relationship 
   -Include at least two has_many through relationships &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2-9qxhCk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50ln7qbzxmcly7j0jqxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2-9qxhCk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50ln7qbzxmcly7j0jqxh.png" alt="Screen Shot 2021-08-07 at 1.53.23 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9iN4rTWV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63nbqkghmzj3ewzav108.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9iN4rTWV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63nbqkghmzj3ewzav108.png" alt="Screen Shot 2021-08-07 at 1.46.52 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Log In/Sign Up: This was one of the harder requirements &lt;br&gt;
because we needed to include a way to log in or sign up &lt;br&gt;
through a third party. I  used Omniauth to include this &lt;br&gt;
feature. This article helped me set it up,  and retrieve the&lt;br&gt;&lt;br&gt;
user information need to log/sign them. &lt;/p&gt;

&lt;p&gt;Omniauth Article Link: &lt;br&gt;
  &lt;a href="https://medium.com/@jenn.leigh.hansen/google-oauth2-for-rails-ba1bcfd1b863"&gt;https://medium.com/@jenn.leigh.hansen/google-oauth2-for-rails-ba1bcfd1b863&lt;/a&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Helper Methods: A helper is a method that has reusable code,&lt;br&gt;&lt;br&gt;
which can be applied to many different places in your rails &lt;br&gt;
app (primarily Controllers and Views).Rails also come with &lt;br&gt;
a set of built-in helper methods. I used 2 helper methods, &lt;br&gt;
which I defined in my Rails-App/app/helpers/application_helper.rb file. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IM0zRQz3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5htkaepofkpspyp892o1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IM0zRQz3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5htkaepofkpspyp892o1.png" alt="Screen Shot 2021-08-07 at 2.06.22 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I placed a line of code in my Applications Controller,  to make sure my helper method could be used on all controllers or views "include ApplicationHelper"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XEFvRgBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ju0bjpx4cs4cd6h6hf1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XEFvRgBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ju0bjpx4cs4cd6h6hf1.png" alt="Screen Shot 2021-08-07 at 2.06.43 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is an example of how the current_user is being used. The screenshot below is of my navigation. I used an if statement to call current_user to make sure there was a current user or user was logged in (I could have also used the logged_in? helper too). This is so that users can see a different nav depending on if you are logged in or not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dr9UUdD7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbwsr4a2b28fyg8gukrv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dr9UUdD7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbwsr4a2b28fyg8gukrv.png" alt="Screen Shot 2021-08-07 at 2.08.33 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scope: Adds a class method for retrieving and querying objects. I use Scope to alphabetize my games by their titles. Scopes are defined in the model that they are used for.  Below is an examples of a scope in the games model. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jfXIz7lx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9maufolztcjblh19aqk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jfXIz7lx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9maufolztcjblh19aqk2.png" alt="Screen Shot 2021-08-07 at 2.15.15 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how the scope is being called in the games controller &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--izwnXZSv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4mjcqx7p1dsrcfn12vs6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--izwnXZSv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4mjcqx7p1dsrcfn12vs6.png" alt="Screen Shot 2021-08-07 at 2.16.05 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the Result:  The games are now in alphabetic order  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jdOVnalz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vjxhtzs5jog4r8omkj5w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jdOVnalz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vjxhtzs5jog4r8omkj5w.png" alt="Screen Shot 2021-08-07 at 2.18.09 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the most difficult things about learning Rails is that there are a lot of moving parts, so things can get messy quickly. With so many views, and models, and associations it can get confusing at times. So some tips that I learned along the way are 1. stay organized by tackling one model and it's views at a time.  2. byebug and binding.pry are lifesavers, so be sure to uses these gems if you are stuck. &lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
    </item>
    <item>
      <title>Sinatra Web APP</title>
      <dc:creator>Bianca Charlotin</dc:creator>
      <pubDate>Sun, 28 Mar 2021 21:21:40 +0000</pubDate>
      <link>https://dev.to/bcharlotin1/sinatra-web-app-4hfe</link>
      <guid>https://dev.to/bcharlotin1/sinatra-web-app-4hfe</guid>
      <description>&lt;p&gt;This blog post will be discussing the process of completing my second flatiron coding project.  It will go into detail on the project I created and the difficulties I encountered. &lt;/p&gt;

&lt;p&gt;This project focused on using Sinatra (which is an alternative to other Ruby web application frameworks such as Ruby on Rails) and developing a web application. As soon I heard the word "web application" my mind went to the many social media sites I've encountered. So it was then that I decided that I would be building the inner workings of a social media site( currently this is nowhere near a fully functional social media site, yet). &lt;/p&gt;

&lt;p&gt;Sinatra was an eye-opener to the world of servers, ULR's, GET and POST requests, etc. Working with Sinatra also help to fortify my attention to detail, specifically when it came to creating forms (in HTML using erb files). While making forms it was important to make sure we understood the name attribute in those forms,  so that we could collect users' input on the back end. Essentially, grasping all of this new information and applying it to our labs was difficult and tedious. &lt;/p&gt;

&lt;p&gt;This project consisted of building Models, Controllers, and Views. &lt;br&gt;
Models are where I created my objects( Users, and Posts) with that I had to establish their relationship (belongs to, has many, etc.) because that would determine where my foreign-key would go or if I need a Join table. Then I created my tables for my database (all done using Active records).&lt;br&gt;&lt;br&gt;
Next, I used my controllers to handle the GET and POST request from the URL.  Also within my controller was the majority of my Ruby code, so I had to:&lt;br&gt;
 Validate the uniqueness of the user login attribute (username or email).&lt;br&gt;
Ensure that the user was signed in and can view certain view pages&lt;br&gt;
Ensure that users can edit and delete only their own resources - not resources created by other users.&lt;br&gt;
create my objects so that I may access them on my view. fils (AKA HTML/erb files)&lt;br&gt;
and much more...&lt;br&gt;
In conjunction with my controller actions, I had to build corresponding Views. This is where the HTML and some minor ruby code would go (Fun Fact: erb files allow you to uses ruby code inside HTML). The View is also what the user will be interacting with, and inputting data for us to collect in our controllers. &lt;/p&gt;

&lt;p&gt;End Result: &lt;br&gt;
I created the beginnings of a social media site called The Hive, where users are able to:&lt;br&gt;&lt;br&gt;
Sign Up&lt;br&gt;
Login&lt;br&gt;
Logout&lt;br&gt;
Create, Edit, or Delete Post &lt;br&gt;
(hope to add more features like a profile View, and add some CSS. to provide for a better UX experience )&lt;/p&gt;

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

</description>
      <category>sideprojects</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Anime CLI Project</title>
      <dc:creator>Bianca Charlotin</dc:creator>
      <pubDate>Wed, 27 Jan 2021 23:42:12 +0000</pubDate>
      <link>https://dev.to/bcharlotin1/anime-cli-project-2lhm</link>
      <guid>https://dev.to/bcharlotin1/anime-cli-project-2lhm</guid>
      <description>&lt;p&gt;This blog post will be discussing the rollercoaster I was on while completing my first flatiron coding project.  It will go into detail on the project I created and the difficulties I encountered. &lt;/p&gt;

&lt;p&gt;When it came to the ideation of this project, I wanted to create a personal aspect that would keep me motivated throughout the process.  Since I'm an avid watcher of Anime shows so I decided to use an Anime API, specifically, the one by Jikan.  From this API. I created a command-line interface(CLI) that acted as a library and would provide the user information for a particular anime. &lt;/p&gt;

&lt;p&gt;After entering the name of the anime you wanted to know about,   displayed in the terminal would be basic information, like title, id, and a synopsis of the show.  Then the user would be prompted and asked if they would like more information, if so, the user would be provided with further details on the show like when it started and when it ended. Lastly, the user would have the option to look at a recommended list of shows based on the anime they searched for. &lt;/p&gt;

&lt;p&gt;Surprisingly, the most difficult part of this project was getting started. Writing the pseudo-code for how this project would interact/work, and understanding the relationships the 3 classes would have was challenging.  This is because typically we would have a spec file that would let us know what was going wrong and if we passed the test.  This time around we had to check every step of the way that everything we were returning was accurate.&lt;/p&gt;

&lt;p&gt;Snippet of the pseudo-code:&lt;/p&gt;

&lt;p&gt;"CLI class" gets an input -&amp;gt; calls on the "API class" and sends it off a request to get information -&amp;gt; "API class" calls on the anime class to create a new object  -&amp;gt; that new object  is what the "CLI Class" will use /output/do something to&lt;/p&gt;

&lt;p&gt;Link to my Github CLI Project: &lt;a href="https://github.com/Bcharlotin1/anime_cli_project"&gt;https://github.com/Bcharlotin1/anime_cli_project&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why I Want to Become a Developer </title>
      <dc:creator>Bianca Charlotin</dc:creator>
      <pubDate>Mon, 14 Dec 2020 16:42:48 +0000</pubDate>
      <link>https://dev.to/bcharlotin1/why-i-want-to-become-a-programer-3ak6</link>
      <guid>https://dev.to/bcharlotin1/why-i-want-to-become-a-programer-3ak6</guid>
      <description>&lt;p&gt;I would like to say that my interest in programming began in college. I was introduced to the many different languages of programming in a web design course where I learned to uses HTML and CSS, and Object-Oriented Programming where I learned the concepts of abstraction, encapsulation, inheritance, and Polymorphism&lt;/p&gt;

&lt;p&gt;With Web Design, I was filled with immediate gratification. You would write a paragraph in HTML, change the background color using CSS,  and like magic it appeared on the screen.  I couldn't say the same for Object-Oriented Programming.  the course was a whole new world for me, it consisted of building many parts for a desired function.  It wasn't as visually striking as web design and that took some to get used to.&lt;/p&gt;

&lt;p&gt;The reason I enjoyed both these classes was because of that feeling you get the moment you made the code to work, it is nothing short of enchanting,  and satisfying at the same time. The reason I kept learning these languages long after college was because, besides a  grade, I had something tangible,  something I created from lines of code that without a text editor would just be syntax. My passion for coding and technology comes from the simple pleaser of finding how to stop your loop from looping to infinity and beyond, or changing how we collaborate by creating web applications like Google Docs. These are the many different reasons why I want to become a software developer. &lt;/p&gt;

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