<?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: Tim Tran</title>
    <description>The latest articles on DEV Community by Tim Tran (@timtran007).</description>
    <link>https://dev.to/timtran007</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%2F945193%2Fd550a4e8-7c02-43d4-b8ed-93a59f9bf4ee.jpeg</url>
      <title>DEV Community: Tim Tran</title>
      <link>https://dev.to/timtran007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/timtran007"/>
    <language>en</language>
    <item>
      <title>Applying for Roles: Coding Assessments... BONUS: How to Deal with Nerves</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Wed, 12 Apr 2023 00:56:57 +0000</pubDate>
      <link>https://dev.to/timtran007/applying-for-roles-coding-assessments-bonus-how-to-deal-with-nerves-44fc</link>
      <guid>https://dev.to/timtran007/applying-for-roles-coding-assessments-bonus-how-to-deal-with-nerves-44fc</guid>
      <description>&lt;p&gt;It's been almost a month into completing Flatiron School's full stack software engineering bootcamp. &lt;/p&gt;

&lt;p&gt;The theme that I can pull away is that as of April 2023, it is tough market out there; however, there are opportunities and you just need to keep looking, networking, and applying, but most importantly keep up with your coding skills (this will payoff in the long run)!&lt;/p&gt;

&lt;p&gt;Once you finally get a response for that coveted software/web development job, there is usually an added layer before the interviews in regards to coding exercises, coding tests, etc.&lt;/p&gt;

&lt;p&gt;This definitely makes sense because companies don't want to hire the right person and sometimes there is no way around it. &lt;/p&gt;

&lt;p&gt;Today let's go ahead and take a look at various formats of coding assessments that I have taken a part in and what it really means!&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding Assessment #1 - Deliverable
&lt;/h2&gt;

&lt;p&gt;By far my favorite type of assessment, where the company will provide a problem statement to solve in addition to a completion date. They leave it up to you to set up your environment and the technology stack that you are comfortable with.&lt;/p&gt;

&lt;p&gt;For lack of better phrasing, the deliverable coding assessment allows for the job seeker to thrive and show off their ability to code and the tools that they use. However, employers will not get a gauge for how job seekers would perform under pressure. &lt;/p&gt;

&lt;h2&gt;
  
  
  Coding Assessment #2 - Timed Tests
&lt;/h2&gt;

&lt;p&gt;This is where nerves can definitely kick in because I was never a great test taker. The SATs... did not do that amazing... CAT-9 standardize test... better luck next time... Accelerated Reader... yeah...&lt;/p&gt;

&lt;p&gt;Growing up I was just a bad test taker; however, I can see how this could be used to filter people that are qualified. Tests in general will show if a person understands the material. But add in a layer of the test being timed, nerves can actually get in the way. &lt;/p&gt;

&lt;p&gt;Whether it is having a new environment to navigate like Test Dome or Hacker Rank, etc... you are limited to the technology the employer chooses.&lt;/p&gt;

&lt;p&gt;All this to say, you need to choose one main language like C-languages, Java, Python, JavaScript etc. My advice would be to choose one and dive deep because some testing sites won't let you reference documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;Don't be like me and decide to do all assessments in one day, especially the timed assessments, no matter how easy the sample questions are... Everything gets blended and you don't know if you could use references or not. &lt;/p&gt;

&lt;p&gt;You heard this advice one too many times, but take a deep breath and tackle one assessment at a time. Failure is okay because it will prepare you for your next assessment. You just need to get out all the bugs and jitters. &lt;/p&gt;

</description>
      <category>juniordev</category>
      <category>continuousimprovement</category>
    </item>
    <item>
      <title>Swapping Databases: SQLite to PostgreSQL for Deployment</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Thu, 23 Mar 2023 23:03:03 +0000</pubDate>
      <link>https://dev.to/timtran007/swapping-databases-sqlite-to-postgresql-for-deployment-248a</link>
      <guid>https://dev.to/timtran007/swapping-databases-sqlite-to-postgresql-for-deployment-248a</guid>
      <description>&lt;p&gt;I am officially graduated from Flatiron School coding bootcamp! But the work is never finished ;)&lt;/p&gt;

&lt;p&gt;One of my goals was to upgrade my projects by deploying them and a couple of weeks ago I created a documentation on how to deploy your Rails &amp;amp; React app with Render for free! You can check out that article &lt;a href="https://dev.to/timtran007/deploying-a-react-rails-app-on-render-4lo4"&gt;here&lt;/a&gt;. This will come in handy later.&lt;/p&gt;

&lt;p&gt;I did some searching, but couldn't find exactly what I was looking for, so here is the compilation of deploying a Rails-React application that uses SQLite3.&lt;/p&gt;

&lt;p&gt;We are going to dive into converting a SQLite3 database into PostgreSQL to deploy projects that you have created with SQLite3. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Swapping out SQLite3 for PG
&lt;/h3&gt;

&lt;p&gt;This first step is based on the assumption that you have postgres installed on your local machine.&lt;/p&gt;

&lt;p&gt;First we need to locate our Gemfile, and make the update to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem "sqlite", "~&amp;gt; 1.4"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem "pg", "~&amp;gt; 1.1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then we are going to run the following in the terminal of the directory:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Update database.yml file
&lt;/h3&gt;

&lt;p&gt;This file will allow us to point to our database within our different levels of environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;default: &amp;amp;default
  adapter: postgresql
  encoding: unicode
  pool: &amp;lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&amp;gt;

development:
  &amp;lt;&amp;lt;: *default
  database: meal_time_app_development

test:
  &amp;lt;&amp;lt;: *default
  database: meal_time_app_test

production:
  &amp;lt;&amp;lt;: *default
  url: &amp;lt;%= ENV['DATABASE_URL'] %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(notice that database is name_of_your_app followed by the respective environment)&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Deleting SQLite3
&lt;/h3&gt;

&lt;p&gt;We are going to look in the db folder and delete the following files development.sqlite3 and test.sqlite3&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Running Migration
&lt;/h3&gt;

&lt;p&gt;We are now going to run the following in our directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:create db:migrate db:reset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Follow the Guide to Deploying a React &amp;amp; Rails App.
&lt;/h3&gt;

&lt;p&gt;You are all set! Now you can follow my previous &lt;a href="https://dev.to/timtran007/deploying-a-react-rails-app-on-render-4lo4"&gt;post&lt;/a&gt; on deploying a Rails-React app using Render!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now enjoy the luxury of deploying your projects on Render by converting your SQLite3 database to PostgreSQL.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Deploying a React-Rails App on Render</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Tue, 14 Mar 2023 06:15:50 +0000</pubDate>
      <link>https://dev.to/timtran007/deploying-a-react-rails-app-on-render-4lo4</link>
      <guid>https://dev.to/timtran007/deploying-a-react-rails-app-on-render-4lo4</guid>
      <description>&lt;p&gt;I can't believe it! I am almost done with my time at Flatiron School, there is a sense of relief, but at the same time thoughts of what the job search is going to be like has been flooding my mind lately. &lt;/p&gt;

&lt;p&gt;What are hiring managers looking for? Do bootcamp graduates have a chance in a market that seems like we are headed into a recession?&lt;/p&gt;

&lt;p&gt;Anyways, after consulting with some people in my network that have been in the industry for quite some time it seems as though the best thing to do is to build applications and deploy to build a portfolio of work!&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Render to Deploy a React-Rails App
&lt;/h2&gt;

&lt;p&gt;Render is an amazing tool that we can use in order to easily deploy applications using React and Rails. Oh did I mention that it is free to use?!&lt;/p&gt;

&lt;p&gt;Anyways, for deployment purposes you can sign up for a Render account &lt;a href="https://dashboard.render.com/register?next=/"&gt;here&lt;/a&gt;! I recommend signing up with your GitHub Account, which will make the process of deploying a lot easier in the future.&lt;/p&gt;

&lt;p&gt;A thing to keep in mind for Render is that you will be utilizing PostgreSQL as your database and you can only have one database instance, but there is a work around here that you want to house multiple databases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a New Database within your Instance
&lt;/h3&gt;

&lt;p&gt;After creating the initial database, right hand corner with Connect and a dropdown, navigate to 'External Connection' and copy and past the PSQL Command into your terminal. &lt;/p&gt;

&lt;p&gt;This will launch the PSQL command line, where we can go ahead and create a new database!&lt;/p&gt;

&lt;p&gt;Run&lt;br&gt;
&lt;code&gt;CREATE DATABASE meal_time_app_db;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;DO NOT FORGET the semicolon... (I forgot this and reached out to their support and they were really nice in asking if I forgot the semicolon)&lt;/p&gt;

&lt;p&gt;Now you can check if a new database has been created by running &lt;br&gt;
&lt;code&gt;\l&lt;/code&gt;&lt;br&gt;
this should show you all the databases within the instance. &lt;/p&gt;
&lt;h3&gt;
  
  
  Configuring Your Rails Application
&lt;/h3&gt;

&lt;p&gt;First open the &lt;code&gt;config/database.yml&lt;/code&gt; and scroll to the production section and update the code to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;production:
  &amp;lt;&amp;lt;: *default
  url: &amp;lt;%= ENV['DATABASE_URL'] %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second, you can open the config/puma.rb file and you can delete everything and paste in the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies the `worker_timeout` threshold that Puma will use to wait before
# terminating a worker in development environments.
#
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers ENV.fetch("WEB_CONCURRENCY") { 4 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
preload_app!

# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

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

&lt;/div&gt;



&lt;p&gt;Third, open the config/environments/production.rb file and find the following line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;update it to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? || ENV['RENDER'].present?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we need to run the following command in the terminal of our app's directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle lock --add -platform x86_64-linux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, inside the bin folder create a file &lt;code&gt;meal-time-build.sh&lt;/code&gt; (your-app-name-build.sh)&lt;/p&gt;

&lt;p&gt;Within this file you can copy and paste the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env bash
# exit on error
set -o errexit

# Add build commands for front end
rm -rf public
npm install --prefix client &amp;amp;&amp;amp; npm run build --prefix client
cp -a client/build/. public/

bundle install
bundle exec rake db:migrate
bundle exec rails db:seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following script above will be used as the build script later. &lt;/p&gt;

&lt;p&gt;But before that we would need to run the following in your app's terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod a+x bin/meal-time-build.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Now We Need to Configure Our React App for Deployment
&lt;/h4&gt;

&lt;p&gt;The ultimate goal is to create a static site consisting of pre-built HTML, JavaScript and CSS files that can be served by Rails when a user makes a request to the server to view the front end. &lt;/p&gt;

&lt;p&gt;So in order create a production version of our React application we will need to run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build --prefix client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we need to move this into our public directory, which are the build commands for our front end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv client/build/* public
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuring Rails for Client-Side Routing
&lt;/h3&gt;

&lt;p&gt;Within our React client, we are using client side routing in our development environment; however, for production we need to ensure that we are rendering the HTMl file for our React application since our routes are mainly for the API.&lt;/p&gt;

&lt;p&gt;To do this we would need to use namespacing to differentiate the API requests from other requests... &lt;/p&gt;

&lt;p&gt;The solution to this issue would be to add a fallback custom route, which job is to render the the HTML file.&lt;/p&gt;

&lt;p&gt;i.e.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rails.application.routes.draw do
    resources :following_ships, only: [:create, :update, :destroy]
    resources :recipes
    resources :shopping_lists
    resources :recipe_ingredients, only: [:create, :update, :destroy]
    resources :ingredients, only: [:create, :update, :destroy]
    get '/users', to: 'users#index'
    get '/user-recipes', to: 'users#user_recipes'
    post '/signup', to: 'users#create'
    get '/me', to: 'users#show'
    post '/login', to: 'sessions#create'
    delete '/logout', to: 'sessions#destroy'
    get '/following-recipes', to: 'following_ships#show_following_recipes'
    post '/follow-user-recipes/', to: 'recipes#follow_user'

  get "*path", to: "fallback#index", constraints: -&amp;gt;(req) { !req.xhr? &amp;amp;&amp;amp; req.format.html? }
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we must create a fallback_controller.rb file within app/controllers and create a method that renders the index.html file...&lt;/p&gt;

&lt;p&gt;i.e.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class FallbackController &amp;lt; ActionController::Base
    def index
      render file: 'public/index.html'
    end
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating New Web Service on Render
&lt;/h3&gt;

&lt;p&gt;Within the Render dashboard, we can click the 'New +' button and then navigate to 'Web Service' to begin the process of deploying our React front end with a Rails back end application. &lt;/p&gt;

&lt;p&gt;We need to ensure that we set the following configurations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;set the Environment to Ruby&lt;/li&gt;
&lt;li&gt;enter the following build command - &lt;code&gt;./bin/meal-time-build.sh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;enter the following for the start command - &lt;code&gt;bundle exec puma -C config/puma.rb&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click 'Advanced' near the bottom of the page...&lt;/li&gt;
&lt;li&gt;Add Environment Variable - &lt;code&gt;DATABASE_URL&lt;/code&gt; as the environment variable. For the value find the Internal Database URL and paste it in, BUT be sure to change the database name at the end to the database that was created &lt;code&gt;~/meal_time_app_db&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add another Environment Variable &lt;code&gt;RAILS_MASTER_KEY&lt;/code&gt;, navigate to the config/master.key to copy and paste value into the value field.&lt;/li&gt;
&lt;li&gt;Then click 'Create Web Service'&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You are done!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;After deploying, you can easily update your React app through committing and pushing new code into the repository. GitHub and Render works seamlessly to automatically deploy new code pushes.&lt;/p&gt;

&lt;p&gt;Enjoy your application as much as I enjoy creating &lt;a href="https://meal-time-app.onrender.com/"&gt;Meal Time&lt;/a&gt;&lt;/p&gt;

</description>
      <category>deployment</category>
      <category>rails</category>
      <category>react</category>
    </item>
    <item>
      <title>Under the Hood: Front End React Form Submission Persisting to a Rails Back End</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Sat, 11 Feb 2023 08:00:19 +0000</pubDate>
      <link>https://dev.to/timtran007/under-the-hood-front-end-react-form-submission-persisting-to-a-rails-back-end-2peg</link>
      <guid>https://dev.to/timtran007/under-the-hood-front-end-react-form-submission-persisting-to-a-rails-back-end-2peg</guid>
      <description>&lt;p&gt;One of the most important things I have learned so far during my journey into Software Development, is that the ability to talk about your code is a very crucial aspect of being a developer. &lt;/p&gt;

&lt;p&gt;At Flatiron School, there are 4 assessments testing students on their knowledge of what they have learned in each phase of the course. &lt;/p&gt;

&lt;p&gt;If I were honest, I felt as though I scathed by my first 3 assessments with the usage of my technical vocabulary. I honestly believed that as I dove deeper through the course the ability to use technical terms to explain my code would be a lot smoother.&lt;/p&gt;

&lt;p&gt;However, earlier today, it finally caught up to me... I did not pass my Phase 4 assessment... &lt;/p&gt;

&lt;p&gt;At first, it was a gut wrench because the thoughts of "is Software Development really for me?", "if I can't pass an assessment, am I good enough to be a developer?" &lt;/p&gt;

&lt;p&gt;Well, imposter syndrome hit hard. I sat staring at my computer trying to figure out what went wrong, but it was a little too late to solve the problem.&lt;/p&gt;

&lt;p&gt;I came to the realization, that the amount of work and effort I put in over the last few months of staying awake into the early morning hours, adjusting my priorities with friends and family will not be done in vain. &lt;/p&gt;

&lt;p&gt;For me, this failure... is an opportunity to learn and quickly move on and improve parts of my skills.&lt;/p&gt;

&lt;p&gt;So, in an effort to get better at thoroughly explaining technical concepts and be held accountable by publishing to the world, let's dive into what is happening with a form submission from the client side to the back end.&lt;/p&gt;

&lt;p&gt;I will be using my phase 4 project &lt;a href="https://github.com/timtran007/restaurant-review-app" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Taking a Look at the Review Form Component
&lt;/h2&gt;

&lt;p&gt;Let's break down what happens with the Review Form after it has been submitted... i.e. our handleSubmit function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleSubmit(e){
        e.preventDefault()
        fetch('/reviews', {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            }, 
            body: JSON.stringify(formData)
        }).then( resp =&amp;gt; {
            if(resp.ok){
                resp.json().then(newReview =&amp;gt; onCreateReview(newReview))
                onHandleSubmit(false)
            } else{
                resp.json().then( error =&amp;gt; setErrors(error.errors))
            }
        })
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First and foremost, we have the event handler handleSubmit that takes in the event parameter, which helps us to execute the preventDefault() method.&lt;/p&gt;

&lt;p&gt;The preventDefault method allows for us to submit the form without reloading the entire page.&lt;/p&gt;

&lt;p&gt;Next we have a fetch post request with the endpoint of '/reviews'. The fetch requests passes the endpoint, method, headers, and body to the back end.&lt;/p&gt;

&lt;h2&gt;
  
  
  From the Front End to Back End in Steps
&lt;/h2&gt;

&lt;p&gt;Before we breakdown the steps, it is very important to understand that our application is set up with a Model, View Controller framework.&lt;/p&gt;

&lt;p&gt;This allows us to build our code in regards to having clearly defined separation of concerns.&lt;/p&gt;

&lt;p&gt;The typical analogy of an MVC is a layout of a restaurant... &lt;/p&gt;

&lt;p&gt;The model is the chef that never interacts with the patrons(view/front end), and we have the waitstaff(controller) communicating between the two. &lt;/p&gt;

&lt;p&gt;The model handles all back end logic from custom methods to associations to validations, etc.&lt;/p&gt;

&lt;p&gt;The view is the front end where users can interact with the application to essentially tell the controller what it needs, and the controller relays the information to the model. &lt;/p&gt;

&lt;p&gt;Once the model interacts with the database, a response is sent  back to the controller and the controller provides the response back to the view.&lt;/p&gt;

&lt;p&gt;Now that we have a high-level overview of the MVC framework, let's dive into what is happening under the hood with our fetch post request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1:
&lt;/h3&gt;

&lt;p&gt;A fetch request is made with the following information: the endpoint, method, header and body in JSON.stringify format. &lt;/p&gt;

&lt;p&gt;And this request is sent to the back end. In the case of my project the back end is built using Ruby on Rails.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fetch('/reviews', {&lt;br&gt;
            method: "POST",&lt;br&gt;
            headers: {&lt;br&gt;
                "Content-Type": "application/json"&lt;br&gt;
            }, &lt;br&gt;
            body: JSON.stringify(formData)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2:
&lt;/h3&gt;

&lt;p&gt;The request is passed to the config/routes.rb file to make sure that a route has been created for the method, end point, controller and its respective action.&lt;/p&gt;

&lt;p&gt;Within my project I have the following in the routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rails.application.routes.draw do
  resources :reviews #let's take a look here
  resources :restaurants, only: [:index, :show]
  post '/signup', to: 'users#create'
  get '/me', to: 'users#show'
  post '/login', to: 'sessions#create'
  delete '/logout', to: 'sessions#destroy'
  get '/user-reviews', to: 'users#user_reviews'
  get '/users-most-reviews/:id', to: 'users#users_most_reviews'
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;resources :reviews&lt;/code&gt;, we have all 5 actions of index, show, create, update and destroy. In this instance we have a POST request to /reviews that is matched to the create action in the Reviews controller.&lt;/p&gt;

&lt;p&gt;To check your routes you can simply type into your terminal:&lt;/p&gt;

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

&lt;p&gt;You can learn more about resources method &lt;a href="https://dev.to/timtran007/rails-routing-resources-vs-resource-gel"&gt;here&lt;/a&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3:
&lt;/h3&gt;

&lt;p&gt;Now the requests travels to the controller and goes through the create action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create
        find_user
        review = find_user.reviews.create!(review_params)
        render json: review, status: :created
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our action will not work unless a user has signed into their account. If a user is not logged in they, will not be able to fill out this review form. &lt;/p&gt;

&lt;p&gt;So, luckily for us, we are logged in, which means that our code is taking a look at the users table to find the id attribute correlated to the user's sessions user_id hash value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4a:
&lt;/h3&gt;

&lt;p&gt;Continuing to follow the order of the code stack, we have the logged in user create a review, which means that the request is now sent to the review model to check the associations and validation for creating a new review record in our database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4b:
&lt;/h3&gt;

&lt;p&gt;But before we can use mass assign the attributes to create the record through this request, we must use strong_params, which is defined within the private method of review_params, to permit the attributes for mass assignment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def review_params
        params.permit(:headline, :rating, :comment, :restaurant_id, :user_id)
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Otherwise, this will not work due to Rails protection against mass assignment vulnerability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5:
&lt;/h3&gt;

&lt;p&gt;As the record is created in our database, our back end code uses render json to convert the model instance into JSON, and since we have a serializer, Rails implicitly will associate the default UserSerializer to the render, where we can customize the output of the json response being prepared to get sent back to the client via the controller action.&lt;/p&gt;

&lt;p&gt;The serializer helps us separate the concerns of our Controller vs. having the controller handle what shouldn't be its responsibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6:
&lt;/h3&gt;

&lt;p&gt;Finally, the JSON response is sent back to the front end, where our code utilizes the .json() to parse the JSON into a JavaScript object for us to handle. &lt;/p&gt;

&lt;p&gt;In this instance using a callback to update our state in a parent component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;As I work towards improving my ability to communicate effectively as a Software Developer, I that there were value information on how the Client-Server relationship works in terms of a form submission that led to a fetch post request!&lt;/p&gt;

</description>
      <category>coding</category>
      <category>codenewbie</category>
      <category>community</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Rails Routing - resources vs. resource Methods</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Sun, 08 Jan 2023 07:12:21 +0000</pubDate>
      <link>https://dev.to/timtran007/rails-routing-resources-vs-resource-gel</link>
      <guid>https://dev.to/timtran007/rails-routing-resources-vs-resource-gel</guid>
      <description>&lt;p&gt;As I am learning more and more about Ruby and Rails, I am beginning unfold CRUD actions and their related behavior in /config/routes.rb file.&lt;/p&gt;

&lt;p&gt;What I have gathered so far is that Rails makes it easy to create routes. You can do it by hand (saved for custom non RESTful routes) or automatically with the resource method (or shall I say resources method... more on this later). &lt;/p&gt;

&lt;p&gt;However, attention to detail is key as I was stuck on trying to pass an rspec test by automatically creating my 6 RESTful routes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Setup
&lt;/h2&gt;

&lt;p&gt;Let's go ahead and set up a new Rails API application (you have Rails installed already)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails new bird-api --api --minimal&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create a new Rails API application for us to work through. &lt;/p&gt;

&lt;p&gt;Then let's go ahead and create our migration and model through the use of Rails generator:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g model Birds name species&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create our migration of a birds table with columns of name and species in string format.&lt;/p&gt;

&lt;p&gt;Then we can go ahead and migrate with:&lt;br&gt;
&lt;code&gt;rails db:migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Great!!&lt;/p&gt;

&lt;p&gt;Let's go ahead and finish up by generating a controller to handle our routes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g controller birds&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating Routes By Hand
&lt;/h2&gt;

&lt;p&gt;Let's go ahead and dive into our routes.rb file and create the routes that we want for our birds controller to provide a JSON rendered response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rails.application.routes.draw do
  #let's handle our routes manually below
  get 'birds', to: 'birds#index'
  get 'birds/:id', to: 'birds#show'
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can do a quick check to see if this works with:&lt;br&gt;
&lt;code&gt;rails routes&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the Controller Actions
&lt;/h2&gt;

&lt;p&gt;Now let's quickly set up our controller actions to handle our RESTful routes of index and show.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class BirdsController &amp;lt; ApplicationController
  #let's go ahead and add our controller actions
  def index
    render json: Bird.all, status: :ok
  end

  def show
    bird = Bird.find(params[:id])
    if bird
      render json: bird, status: :ok
    else
      render json: {error: "bird not found"}, status: 
      :not_found
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! We can check to see if this works by adding seed data and seeding our application.&lt;/p&gt;

&lt;p&gt;Then we can spin up our server:&lt;/p&gt;

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

&lt;p&gt;For our RESTful route for /birds, we should see something similar (dependent upon seed data):&lt;/p&gt;

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

&lt;p&gt;And for our RESTful route for /birds/:id, we should see:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Let's Automate Our RESTful Routes With resource
&lt;/h2&gt;

&lt;p&gt;Great! Now let's refactor our code to automate the Routes.&lt;/p&gt;

&lt;p&gt;We can do this by going into our config directory and routes.rb file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rails.application.routes.draw do
  #manual way to create our route
    #get 'birds', to: 'birds#index'
    #get 'birds/:id', to: 'birds#show'
  #automated way to create our routes
    resource :birds, only: [:index, :show]
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go ahead and check our routes to make sure that we got our two routes by running:&lt;br&gt;
&lt;code&gt;rails routes&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Oh no!! We only have one route for our birds controller with the action of show...&lt;/p&gt;

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

&lt;p&gt;Why do we only have one route created?&lt;/p&gt;

&lt;h2&gt;
  
  
  'resource' Method vs. 'resources' Method
&lt;/h2&gt;

&lt;p&gt;Like I mentioned before... attention to detail is the key here. By not adding an 's' to the end of 'resource' method we only generate the show action for the birds controller in the code above.&lt;/p&gt;

&lt;p&gt;Let's take a deeper look into the RESTful routes created if we run just &lt;code&gt;resource :birds&lt;/code&gt; instead of the additional `only: [:index, :show]...&lt;/p&gt;

&lt;p&gt;We get only 5 RESTful routes that do not make sense at all:&lt;/p&gt;

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

&lt;p&gt;As you can see there are actions for our birds controller for updating and destroying all birds... With RESTful routes conventions, we must target a specific bird to update and destroy.&lt;/p&gt;

&lt;p&gt;Now let's go ahead and take a look at if we used the 'resources' method instead:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Rails.application.routes.draw do&lt;br&gt;
  resources :birds&lt;br&gt;
end&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We get 6 RESTful Routes that actually makes sense! Two for our &lt;code&gt;/birds&lt;/code&gt; and four for individual birds &lt;code&gt;/bird&lt;/code&gt;:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We can solve the problem of creating our birds controller action of index and show by simply writing:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;resources :birds, only: [:index, :show]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Rails provides easy ways to automate tedious tasks such as creating routes, but it can get tricky at times troubleshooting since you don't necessarily get an outright error that says don't use 'resource', instead use 'resources'. &lt;/p&gt;

&lt;p&gt;The devil is in the details, as I struggled to pass my rspec tests all because I left out the 's' in resources. I hope you can learn from my experience of troubleshooting the automation of creating RESTful routes.&lt;/p&gt;

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

&lt;p&gt;Use &lt;code&gt;resources :controllers_name&lt;/code&gt; and not &lt;code&gt;resource :controllers_name&lt;/code&gt; when automating the creation of RESTful routes.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>api</category>
      <category>beginners</category>
    </item>
    <item>
      <title>It's a Read Action, Not a GET Request in Full Stack Development</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Fri, 16 Dec 2022 22:37:36 +0000</pubDate>
      <link>https://dev.to/timtran007/its-a-read-action-not-a-get-request-in-full-stack-development-1m9g</link>
      <guid>https://dev.to/timtran007/its-a-read-action-not-a-get-request-in-full-stack-development-1m9g</guid>
      <description>&lt;p&gt;Object Oriented programming in Ruby has been the toughest section to grasp so far in my journey of learning how to code, but it has been one of the most rewarding.&lt;/p&gt;

&lt;p&gt;Since the last time I have written (&lt;a href="https://dev.to/timtran007/a-marketers-take-on-client-side-routing-with-react-router-4n1b"&gt;Client-Side Routing w/ React Router&lt;/a&gt;), it has been a full-circle experience with dabbling in full stack development. Since my journey since September of 2022, I have been developing my skills to build both front end applications and back end applications while leveraging React as the front end library and Sinatra and Active Record as my back end API application.&lt;/p&gt;

&lt;p&gt;Throughout this journey, I picked up a magical tip that shows the true power of the back end development, when performing a GET request with a React app.&lt;/p&gt;

&lt;p&gt;You can follow along by cloning my Phase 3 Project: Dog Adventures -&amp;gt;&lt;br&gt;
&lt;a href="https://github.com/timtran007/phase-3-project-dog-adventures-client" rel="noopener noreferrer"&gt;Front End React App&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/timtran007/phase-3-project-dog-adventures-app-server" rel="noopener noreferrer"&gt;Back End API Server&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So let's jump into it as I break down how to write CRUD actions in your controllers file with Sinatra.&lt;/p&gt;
&lt;h2&gt;
  
  
  What does the 'R' stand for in CRUD?
&lt;/h2&gt;

&lt;p&gt;Before we go answering the question of this header... Let's take a moment to define what CRUD actions are and their corresponding HTTP verbs. &lt;/p&gt;

&lt;p&gt;CREATE = "POST"&lt;br&gt;
? = "GET"&lt;br&gt;
Update = "PATCH"&lt;br&gt;
Destroy = "DELETE"&lt;/p&gt;

&lt;p&gt;Yes you guessed it! R is Read within CRUD actions and the corresponding HTTP verb is GET. &lt;/p&gt;

&lt;p&gt;Let's talk about the differences between the actual CRUD action of 'READ' and the 'GET' HTTP verb and how to use it in correspondence with regards to full stack development.&lt;/p&gt;
&lt;h2&gt;
  
  
  The GET Fetch Request
&lt;/h2&gt;

&lt;p&gt;The GET fetch request is utilized in both the front end and the back end. &lt;/p&gt;

&lt;p&gt;As far as a React application goes the general setup is basically leveraging the useEffect() prop from React:&lt;br&gt;
&lt;/p&gt;

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

const [dogs, setDogs] = useState([])

useEffect(() =&amp;gt; {
  fetch('http://localhost:9292/dogs')
  .then(resp =&amp;gt; resp.json())
  .then(data =&amp;gt; setDogs(data)
}, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, we are essentially creating a GET fetch request that pulls information from our Back End API Server to set the state of dogs as an array information from the dogs table.&lt;/p&gt;

&lt;p&gt;This is pretty basic enough! So let's go ahead and take a look at our application_controller.rb file in the back end application to see how GET fetch request is mapped out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#application_controller.rb

class ApplicationController &amp;lt; Sinatra::Base
  set :default_content_type, 'application/json'

  get '/dogs' do
    dogs = Dog.all
    dogs.to_json
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, this isn't crazy stuff here, it's pretty basic to where you are mapping the action of the front end's GET request to pull all dogs into state.&lt;/p&gt;

&lt;p&gt;Below is what we get when we open up &lt;a href="http://localhost:9292/dogs" rel="noopener noreferrer"&gt;http://localhost:9292/dogs&lt;/a&gt; in our browser:&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%2Fwhtc6009dzw0tt69kjcy.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%2Fwhtc6009dzw0tt69kjcy.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We get a basic JSON file that give us information about dogs in our database that we can use in our Front End application. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Difference Between Read and GET
&lt;/h2&gt;

&lt;p&gt;The concept of Read is reading our entire back end application that includes our associations. &lt;/p&gt;

&lt;p&gt;Within our back end, we have two models -&amp;gt; &lt;/p&gt;

&lt;p&gt;Dog&lt;br&gt;
&amp;amp;&lt;br&gt;
Adventure&lt;/p&gt;

&lt;p&gt;Each dog has many adventures and each adventure belongs to a dog.&lt;/p&gt;

&lt;p&gt;With this in mind, if we were to GET information we could create the same mapped out action for our adventures... But if we scaled and had a big application with a lot of data, running the GET fetch request through our front end multiple times could be costly.&lt;/p&gt;

&lt;p&gt;So if we want to Read from both models and run GET once in our Front End and save everything else to state to have access, then how would we do this?&lt;/p&gt;
&lt;h2&gt;
  
  
  Relationship Associations
&lt;/h2&gt;

&lt;p&gt;Let's take a look at our mapped out GET request for /dogs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#application_controller.rb

class ApplicationController &amp;lt; Sinatra::Base
  set :default_content_type, 'application/json'

  get '/dogs' do
    dogs = Dog.all
    dogs.to_json
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you see the .to_json method allows us to use a power feature: &lt;code&gt;include:&lt;/code&gt; which will nest a &lt;code&gt;has_many&lt;/code&gt; relationship into the hash.&lt;/p&gt;

&lt;p&gt;i.e. if we had:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get '/dogs' do
    dogs = Dog.all
    dogs.to_json(include: :adventures)
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we have access to an array of hashes with all of our dogs and their corresponding adventures nested in their hash.&lt;/p&gt;

&lt;p&gt;Let's take a look now at our API:&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%2Foiiwp37lcwm44vb5mkca.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%2Foiiwp37lcwm44vb5mkca.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, our front end can now have access to all this rich data based on just 1 GET fetch request.&lt;/p&gt;

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

&lt;p&gt;Don't run multiple GET fetch requests in your front end.&lt;/p&gt;

&lt;p&gt;Access the power of your back end API by simply associating models in your controllers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get '/object_tables' do
  objects = Object.all
  objects.to_json(include: :second_tables)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sinatra</category>
      <category>controllers</category>
      <category>react</category>
      <category>crud</category>
    </item>
    <item>
      <title>A Marketer's Take on Client-Side Routing with React Router</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Mon, 07 Nov 2022 03:39:14 +0000</pubDate>
      <link>https://dev.to/timtran007/a-marketers-take-on-client-side-routing-with-react-router-4n1b</link>
      <guid>https://dev.to/timtran007/a-marketers-take-on-client-side-routing-with-react-router-4n1b</guid>
      <description>&lt;p&gt;Currently, I am learning the ins and outs of ReactJS. I have built a minimal viable product using React called &lt;a href="https://github.com/timtran007/phase-02-project-tripsave"&gt;TripSave&lt;/a&gt;. It is a mock application where you can add a destination, budget, current savings and an inspiring destination image to work towards that goal of saving for that trip. &lt;/p&gt;

&lt;p&gt;Anyways, throughout learning React, I have been building Single-Page Applications (SPAs) as practice to get really familiar with syntax and learn how to solve common problems for features such as controlled forms, when to create states, use props, perform CRUD actions, etc. However, one thing that I have noticed while writing React code is that these SPAs do not mimic a "traditional" website in regards to changing the browser's URL when routing to a different portion of the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  First of All... What is Routing?
&lt;/h2&gt;

&lt;p&gt;Routing is where users are navigated to different pages on a website.&lt;/p&gt;

&lt;p&gt;Normally, with web pages built with HTML, CSS and vanilla JavaScript, each page created for the website lives on a server. The website uses server-side routing in order to send a GET fetch request to the server each time users navigate to different pages and this changes the URL path in the browser's URL.&lt;/p&gt;

&lt;p&gt;However, with client-side routing, there is only one request sent to the server at the beginning, which pulls in all the data and code necessary to conditionally render the Single-Page-Application based on features within the web application itself. Like mentioned before, this does not change the URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  React &amp;amp; Routing
&lt;/h2&gt;

&lt;p&gt;By default, there is a lot of code and work around that would go into making client-side routing mimic server-side routing within a React application. &lt;/p&gt;

&lt;p&gt;We won't get into those details today...&lt;/p&gt;

&lt;p&gt;However, we will be talking about an awesome library that was made specifically to handle routing in React that mimics a server-side approach of changing the URL's path in the browser  that users have grown accustomed to in a traditional website, while providing a better user experience. &lt;/p&gt;

&lt;h2&gt;
  
  
  Pros &amp;amp; Cons of Client-Side Routing
&lt;/h2&gt;

&lt;p&gt;So let's dive right into it...&lt;/p&gt;

&lt;p&gt;Pros: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better user experience with "lightning fast" speed while navigating through different components ("pages")&lt;/li&gt;
&lt;li&gt;Developers can create animations in between the load of components allowing users to see that data is loading in a fun way. &lt;/li&gt;
&lt;li&gt;As users navigate through the React application, there are no refreshes or reloads of the "pages". Components are rendered quickly and does not need to talk to the server to serve new user interfaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The initial load time could be a bit longer, since the app is making one request server request to get all data into its components. &lt;/li&gt;
&lt;li&gt;Harder to implement web analytics tracking with Single-Page-Applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a marketer since 2016 exploring programming, at the end of the day, we should take into consideration the end users. Therefore in my opinion, when the circumstance is right, having the appearance of lightning fast speed across navigating the website outweighs doing more work to implement web analytics (been there and done that with Google Analytics &amp;amp; Tag Manager). &lt;/p&gt;

&lt;p&gt;With that, let's dive into how to create client-side routing for a React application with React Router!&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing React Router
&lt;/h2&gt;

&lt;p&gt;React Router is a library created to deliver a better user experience for React applications by allowing users to create Route components that allows users to navigate to "different" portions of the application. &lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;First let's make sure you have the latest version of npm&lt;/p&gt;

&lt;p&gt;In terminal you could do the following you can check the version of npm by writing:&lt;br&gt;
&lt;code&gt;npm -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you need the latest version you can write this into terminal:&lt;br&gt;
&lt;code&gt;npm install -g npm&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Assuming that you have a React project already, go ahead and type the following into terminal in order download React Router version 5 package:&lt;br&gt;
&lt;code&gt;npm install react-router-dom@5&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Adding React Router to your React Application.
&lt;/h3&gt;

&lt;p&gt;There are a few components that are important in making client-side routing with React Router with your React application: BrowserRouter, Switch, Route and NavLink(Link).&lt;/p&gt;
&lt;h4&gt;
  
  
  BrowserRouter Component
&lt;/h4&gt;

&lt;p&gt;The BrowserRouter component allows you to wrap the components you would like to use add routing. Usually this would be the top-level component.&lt;/p&gt;

&lt;p&gt;So, let's go ahead and start by importing the BrowserRouter component to your top-level component and wrapping the component around the App component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import {BrowserRouter} from 'react-router-dom'
import Nav from "./Nav"

function App(){
  return(
    &amp;lt;BrowserRouter&amp;gt;
      &amp;lt;h1&amp;gt;Welcome to the App&amp;lt;/h1&amp;gt;
      &amp;lt;Nav /&amp;gt;
    &amp;lt;/BrowserRouter&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Switch &amp;amp; Route Components
&lt;/h4&gt;

&lt;p&gt;The Switch component makes sure that we only render one Route at a time, while the Route component tells us which component will be rendered on the path that matches the URL.&lt;/p&gt;

&lt;p&gt;Route is one of the most important components within React Router and it requires the need for a prop called exact to exactly match the path.. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Route exact path="/"&amp;gt;{Home}&amp;lt;/Route&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you do not have the exact prop attached you will not be able to route to other pages because Switch is rendering only one and the Route that matches first, so if you have a path of '/', which is home (normally), without the prop you will not be able to access '/about'.&lt;/p&gt;

&lt;p&gt;Let's go ahead and add the components to our code above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import {BrowserRouter, Switch, Route} from 'react-router-dom'
import Nav from './Nav'
import Home from './
import Location from './Location'
import About from './About'

function App(){
  return(
    &amp;lt;BrowserRouter&amp;gt;
      &amp;lt;Nav /&amp;gt;
      &amp;lt;Switch&amp;gt;
        &amp;lt;Route exact path="/"&amp;gt;{Home}&amp;lt;/Route&amp;gt;
        &amp;lt;Route path="/location"&amp;gt;{Location}&amp;lt;/Route&amp;gt;
        &amp;lt;Route path="/about"&amp;gt;{About}&amp;lt;/Route&amp;gt;
      &amp;lt;/Switch&amp;gt; 
    &amp;lt;/BrowserRouter&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Should I Use the Link or NavLink Component?
&lt;/h4&gt;

&lt;p&gt;The Link and NavLink components act like the anchor tags and href attribute. The difference between Link and NavLink is the whether you want the selected link to be highlighted our not. &lt;/p&gt;

&lt;p&gt;If you do, you can use NavLink with the prop of activeClassName to see what is currently showing. Otherwise, they have the same functionality. &lt;/p&gt;

&lt;p&gt;So let's go ahead and add the NavLinks to our Nav.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import {NavLink} from 'react-router-dom'

function Nav(){
  return(
    &amp;lt;nav&amp;gt;
      &amp;lt;ul&amp;gt;
        &amp;lt;li&amp;gt;
          &amp;lt;NavLink to="/" activeClassName="active"&amp;gt;
          Home
          &amp;lt;/NavLink&amp;gt;
        &amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;
          &amp;lt;NavLink to="/location" activeClassName="active"&amp;gt;
          Location
          &amp;lt;/NavLink&amp;gt;
        &amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;
          &amp;lt;NavLink to="/about" activeClassName="active"&amp;gt;
          About
          &amp;lt;/NavLink&amp;gt;
        &amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
    &amp;lt;/nav&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Again, client-side routing can provide an amazing experience for users navigating through a Single-Page Application with "lightning fast" speeds rendering various components based on routes. &lt;/p&gt;

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

&lt;h3&gt;
  
  
  Using BrowserRouter, Switch &amp;amp; Route Components
&lt;/h3&gt;

&lt;p&gt;Use BrowserRouter component to wrap the top-level component where you want to use Routes.&lt;/p&gt;

&lt;p&gt;Use Switch and Route components to create paths for components that match what you want to see in browser's URL, while making sure it loads one Route at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import {BrowserRouter, Switch, Route} from 'react-router-dom'
import Nav from './Nav'
import Home from './
import Location from './Location'
import About from './About'

function App(){
  return(
    &amp;lt;BrowserRouter&amp;gt;
      &amp;lt;Nav /&amp;gt;
      &amp;lt;Switch&amp;gt;
        &amp;lt;Route exact path="/"&amp;gt;{Home}&amp;lt;/Route&amp;gt;
        &amp;lt;Route path="/location"&amp;gt;{Location}&amp;lt;/Route&amp;gt;
        &amp;lt;Route path="/about"&amp;gt;{About}&amp;lt;/Route&amp;gt;
      &amp;lt;/Switch&amp;gt; 
    &amp;lt;/BrowserRouter&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using NavLink or Link Components
&lt;/h3&gt;

&lt;p&gt;Use NavLink or Link to create "anchor tags" with the "to" prop to point where the link takes a user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import {NavLink} from 'react-router-dom'

function Nav(){
  return(
    &amp;lt;nav&amp;gt;
      &amp;lt;ul&amp;gt;
        &amp;lt;li&amp;gt;
          &amp;lt;NavLink to="/" activeClassName="active"&amp;gt;
          Home
          &amp;lt;/NavLink&amp;gt;
        &amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;
          &amp;lt;NavLink to="/location" activeClassName="active"&amp;gt;
          Location
          &amp;lt;/NavLink&amp;gt;
        &amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;
          &amp;lt;NavLink to="/about" activeClassName="active"&amp;gt;
          About
          &amp;lt;/NavLink&amp;gt;
        &amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
    &amp;lt;/nav&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>clientsiderouting</category>
      <category>react</category>
      <category>reactrouter</category>
    </item>
    <item>
      <title>Adding an Event Listener to DOM Manipulated Data Fetch(ed) from a JSON API</title>
      <dc:creator>Tim Tran</dc:creator>
      <pubDate>Sun, 16 Oct 2022 04:10:41 +0000</pubDate>
      <link>https://dev.to/timtran007/adding-an-event-listener-to-dom-manipulated-data-fetched-from-a-json-api-3ffj</link>
      <guid>https://dev.to/timtran007/adding-an-event-listener-to-dom-manipulated-data-fetched-from-a-json-api-3ffj</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR:
&lt;/h2&gt;

&lt;p&gt;As a person who has been learning JavaScript for the last 3-4 weeks, here is my take on adding an event listener to a newly created elements through DOM Manipulation from a JSON API fetch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let databaseURL = '_**url of your json data file**_'
let areaInHTMLToAppend = document.querySelector('_**id or class of areaInHTMLToAppend**_')

function fetchData(){
 fetch(databaseURL)
 .then(resp =&amp;gt; resp.json())
 .then(data =&amp;gt; {
  appendData(data)
  addingEventListener()
 })
}

function appendData(array){
 array.forEach(data =&amp;gt; {
  let fetchedData = document.createElement('div')
  fetchedData.className = 'fetched-data-class'
  fetchedData.innerHTML =`
   _**//HTML manipulation**_
  `
 areaInHTMLToAppend.appendChild(fetchedData)
 })
}

function addingEventListener(){
const newlyCreatedElements = document.querySelectorAll('.fetched-data-class')
newlyCreatedElements.forEach(element =&amp;gt; {
 element.addEventListener('**_eventListener_**', _**callback**_)
})
}

function callback() =&amp;gt; {
 **_console.log('x')_**
}

fetchData()

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;It was 9:27 PM and I had just gotten done with a zoom session with a technical coach explaining the basis of my code and how I was going to fetch data from the API and manipulate the DOM with this new set of data to assign it.&lt;/p&gt;

&lt;p&gt;It was exhilarating! I rushed over to my spouse and told her that I am finally getting it. 3 weeks in and coding is pretty  easy once everything clicks. &lt;/p&gt;

&lt;p&gt;I thought to myself, I must be a genius let me take a couple of hours and unwind and pick this up again. &lt;/p&gt;

&lt;p&gt;But little did I know at the time my thoughts and plan came back to haunt me...&lt;/p&gt;

&lt;p&gt;It was now 2:13 AM and I am banging my head against the computer asking why my code isn't working. I totally thought I had the data manipulation correct, but I was missing a crucial piece.&lt;/p&gt;

&lt;h2&gt;
  
  
  My crucial mistake
&lt;/h2&gt;

&lt;p&gt;I kept getting a TypeError that array.forEach() is not a function... &lt;/p&gt;

&lt;p&gt;What did I do wrong? What can I do? My notes that I was taking didn't have this TypeError... I didn't know what to Google and I am taking my array and iterating on it, so why isn't it working!?!? I reached out to the Flatiron School community on slack and it was a humbling experience. &lt;/p&gt;

&lt;p&gt;The next day, I learned that I was not accessing my array correctly.&lt;/p&gt;

&lt;p&gt;Some wise words of advice if you get TypeError array.forEach() is not a function:&lt;/p&gt;

&lt;p&gt;CHECK YOUR ARRAY/OBJECT/DATA you are trying to iterate on...&lt;/p&gt;

&lt;p&gt;Are you accessing the right information with dot notation? Are you just pulling in the database as a whole?&lt;/p&gt;

&lt;h2&gt;
  
  
  console.log() is your friend
&lt;/h2&gt;

&lt;p&gt;In order to answer the pivotal question above, use a console.log&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchOngoingRecall(){
    fetch ('https://api.fda.gov/food/enforcement.json?limit=1000')
    .then(resp =&amp;gt; resp.json())
    .then(data =&amp;gt; {
        console.log(data)
    })
}

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

&lt;/div&gt;



&lt;p&gt;Now you can see where the array/object of the data really lies. &lt;/p&gt;

&lt;p&gt;In my example, the data retrieved from the .json() method had the arrays in the results. &lt;/p&gt;

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

&lt;p&gt;So how do you access the array?&lt;/p&gt;

&lt;h1&gt;
  
  
  You Can Use Dot Notation
&lt;/h1&gt;

&lt;p&gt;Do this to iterate on the example above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchOngoingRecall(){
    fetch ('https://api.fda.gov/food/enforcement.json?limit=1000')
    .then(resp =&amp;gt; resp.json())
    .then(data =&amp;gt; {
        console.log(data)
        data.results.forEach(product =&amp;gt;{
            console.log(product)
        }
    })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way you can access the array and manipulate the right data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why We Are Really Here
&lt;/h2&gt;

&lt;p&gt;Now let's talk about adding adding an event listener to a DOM Manipulated element that was fetch(ed) from the JSON API.&lt;/p&gt;

&lt;p&gt;Below is some code that manipulates the data to add into the DOM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let databaseURL = '_**url of your json data file**_'
let areaInHTMLToAppend = document.querySelector('_**id or class of areaInHTMLToAppend**_')

function fetchData(){
 fetch(databaseURL)
 .then(resp =&amp;gt; resp.json())
 .then(data =&amp;gt; {
  appendData(data)
 })
}

function appendData(array){
 array.forEach(data =&amp;gt; {
  let fetchedData = document.createElement('div')
  fetchedData.className = 'fetched-data-class'
  fetchedData.innerHTML =`
   _**//HTML manipulation**_
  `
 areaInHTMLToAppend.appendChild(fetchedData)
 })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above we have created a div for each fetchedData, assigned it the .fetch-data-class and we appended each fetchedData into our designated area to append with the areaInHTMLToAppend variable.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please note the className assignment is important as we will use it for adding our event listener.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Our Event Listener
&lt;/h2&gt;

&lt;p&gt;Easy steps to add an event listener... &lt;/p&gt;

&lt;p&gt;Let's begin by creating a variable that selects all of our new  divs with the class name of .fetched-data-class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addingEventListener(){
  const newlyCreatedElements = 
  document.querySelectorAll('.fetched-data-class')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It would be very tempting to just add the .addEventListener method to the newly created elements.&lt;/p&gt;

&lt;p&gt;If we do we are going to get hit with another TypeError that newlyCreatedElements.addEventListener() is not a function...&lt;/p&gt;

&lt;p&gt;Let's go back to my crucial mistake from before. &lt;/p&gt;

&lt;p&gt;You cannot just add an event listener to a nodeList or an array-like object, you would have to iterate on it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;So here is the solution:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addingEventListener(){
  const newlyCreatedElements = 
  document.querySelectorAll('.fetched-data-class')
  newlyCreatedElements.forEach(element =&amp;gt; {
    element.addEventListener('**_eventListener_**', _**callback**_)
  })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We must use forEach to go through the nodeList and add the event listener to each element and you can listen for any events and create a callback function that you would like.&lt;/p&gt;

&lt;h2&gt;
  
  
  In Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this post can help you on your coding journey. &lt;/p&gt;

&lt;p&gt;If you are learning on your own, the best advice I can give you is try building a community of people to help you through this journey. &lt;/p&gt;

&lt;p&gt;For me, joining Flatiron School's bootcamp helped me to realize that it is great to have a community to learn and go through this journey in becoming a software developer, plus I can get expert guidance and advice from instructors and technical coaches when I'm really stuck!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
