<?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: Allison Kim</title>
    <description>The latest articles on DEV Community by Allison Kim (@allisonkim).</description>
    <link>https://dev.to/allisonkim</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%2F903351%2F0226cc86-40b3-4304-9752-0db139d3481d.jpg</url>
      <title>DEV Community: Allison Kim</title>
      <link>https://dev.to/allisonkim</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/allisonkim"/>
    <language>en</language>
    <item>
      <title>Indexes in SQL {Using Rails}</title>
      <dc:creator>Allison Kim</dc:creator>
      <pubDate>Tue, 11 Oct 2022 14:39:37 +0000</pubDate>
      <link>https://dev.to/allisonkim/indexes-in-sql-using-rails-4ni9</link>
      <guid>https://dev.to/allisonkim/indexes-in-sql-using-rails-4ni9</guid>
      <description>&lt;p&gt;Indexing in SQL is a useful tool to make querying database tables much faster and easier. It is ideal for when you plan to have large amounts of data in your table and often need to extract that data by certain column values. For example, when a record requires a different, maybe formatted, ID than what's auto-assigned in the database table, or you want to be able to pull a set of records by its value in a category column, indexing is the perfect tool.&lt;/p&gt;

&lt;p&gt;You might be thinking, "Why not just use the WHERE clause?" The WHERE clause is not ideal because it causes the database engine to look through every single record in the table. This can result in a substantial amount of search time, especially if you have a table with, say, a million records (which is not hard to have). Why waste that kind of time when you can reduce it to one second with this simple step?&lt;/p&gt;

&lt;p&gt;To add an index to a column via Rails Migration:&lt;/p&gt;

&lt;p&gt;When first creating your table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create_table :table_name do |t|
  t.integer :column_name_one, index: true
  t.string :column_name_two, index: true
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your column already exists:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add_index :table_name, :column_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What's happening under the hood when you create indices is: a new table gets created to store each row's value of the indexed column and a pointer to its location in the database. Although it may seem like a questionable trade-off between storage and search time, the new table is considerably small in width since it only stores the index and pointer and not the records themselves. Then, when you use an index in your query, the database engine is able to use the newly created table to quickly obtain those records, instead of searching through every record one-by-one. As one might say, the benefits outweigh the cost.&lt;/p&gt;

&lt;p&gt;There are more ways to modify an index to benefit your querying further, which are greatly outlined &lt;a href="https://api.rubyonrails.org/v7.0.4/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_index"&gt;here&lt;/a&gt;. So be sure to check them out when you start implementing indexes in your tables. Hope this helped!&lt;/p&gt;

</description>
      <category>sql</category>
      <category>rails</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>We Love Ruby {Method Chaining}</title>
      <dc:creator>Allison Kim</dc:creator>
      <pubDate>Fri, 16 Sep 2022 15:56:18 +0000</pubDate>
      <link>https://dev.to/allisonkim/we-love-ruby-method-chaining-1f78</link>
      <guid>https://dev.to/allisonkim/we-love-ruby-method-chaining-1f78</guid>
      <description>&lt;p&gt;A lot of developers love programming in Ruby because of its simplified and almost colloquial nature. For example, a line of Ruby code could read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;my_age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Unable to purchase alcohol"&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;my_age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can almost read it in normal English as "Put out to the terminal 'Unable to purchase alcohol' unless my age is greater than or equal to 21."&lt;/p&gt;

&lt;p&gt;This was Ruby designer, Yukihiro "Matz" Matsumoto's goal: to make a language that's ultimately easy to use, intuitive to write, and make programmers happy.&lt;/p&gt;

&lt;p&gt;I found I love Ruby through how simplified a complex line of code can become with Ruby's style of &lt;strong&gt;method chaining&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Method chaining is a convenient way to build up complex queries, which are then lazily executed when needed. Within the chain, a single object is updated and passed from one method to the next, until it's finally transformed into its output value.&lt;/p&gt;

&lt;p&gt;-Jeff Kreeftmeijer&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's go through a fun example together:&lt;/p&gt;

&lt;p&gt;To set the stage, let's say we are a clothing store and we're using Ruby (along with ActiveRecord) to build and access a SQL database. For our framework, we have a one-to-many relationship between each customer and the products he/she purchases -- i.e., a product can only belong to one customer, but a customer can have many products. In our schema (SQL table build), each customer is given a unique ID, and the products table has the customer ID as a foreign key for each product.&lt;/p&gt;

&lt;p&gt;Now, we - as the store - want to reward our most $$ lucrative $$ customer (the one who's bought the most products) with a gift as a thank you for all the business. In psuedocode, the way to do this is by counting all the products each customer has purchased and grabbing the customer with the max count. Solution here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joins&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:products&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max_by&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;}[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="no"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;code&gt;Customer&lt;/code&gt; is the class we define to represent our customer model.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;joins(:products)&lt;/code&gt; performs a SQL INNER JOIN to compile a list of customers where the respective customer from each product in the products table is returned.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;group(:id)&lt;/code&gt; combines any repeating elements that share the same value in the column defined by the argument. In this case, it combines any customers that share the same unique ID and returns a list of unique customers.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;count&lt;/code&gt; returns a count of elements in a list. But when applied in conjunction with &lt;code&gt;group&lt;/code&gt;, it provides a count of repeating elements for each unique element. This is returned in a key-value pair for each unique element, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# format: {id=&amp;gt;count}&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;2&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;where element ID 1 has a count of 2, element ID 2 has a count of 1, and so on.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;max_by { |obj| block }&lt;/code&gt; returns the object with the maximum value based on the &lt;code&gt;block&lt;/code&gt; condition. In our solution, we're taking each object (&lt;code&gt;{id,count}&lt;/code&gt;) returned by the &lt;code&gt;count&lt;/code&gt; method to return the object with the maximum count. The object is returned in array format, &lt;code&gt;[id, count]&lt;/code&gt; - thus, we tack on &lt;code&gt;[0]&lt;/code&gt; at the end of our solutionto only grab the ID.&lt;/p&gt;

&lt;p&gt;Now that we have the ID of the customer with the most amount of products, we can use the &lt;code&gt;find(id)&lt;/code&gt; method on the Customer class to return the instance of that customer. And that's it!&lt;/p&gt;

&lt;p&gt;It's your turn to experiment and further discover the power of method chaining in Ruby! Happy coding!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>sql</category>
    </item>
    <item>
      <title>Where did my data go? {React Router}</title>
      <dc:creator>Allison Kim</dc:creator>
      <pubDate>Fri, 26 Aug 2022 04:29:00 +0000</pubDate>
      <link>https://dev.to/allisonkim/where-did-my-data-go-react-router-4p59</link>
      <guid>https://dev.to/allisonkim/where-did-my-data-go-react-router-4p59</guid>
      <description>&lt;p&gt;In this post, I'll be talking about an intricate nest of problems I dealt with while learning how to use React Router that took some time debugging and troubleshooting to understand.&lt;/p&gt;

&lt;p&gt;To set the stage, a fellow developer and I were tasked with building a single-page application that utilizes client-side routing to render a different 'page' on the DOM with each route.&lt;/p&gt;

&lt;p&gt;We built an application that accesses a free &lt;a href="https://pokeapi.co/"&gt;Pokémon API&lt;/a&gt; to render a Pokémon library as one route and a personal Pokédex as another route. The library lists the first 386 Pokémon from the API and the Pokédex lists whatever Pokémon the user saved (or caught, if you will). The user can also click on any of the Pokémon to link and route to a detailed page of that Pokémon. Each route has its own unique URL, including each route to a specific Pokémon (i.e. clicking on the Pikachu would change the URL to localhost:####/pikachu).&lt;/p&gt;

&lt;p&gt;That was all well and done -- until we tried routing to the detailed Pokémon page by &lt;em&gt;manually&lt;/em&gt; typing a Pokémon in the URL. The Pokémon data was not passing down and the page would show nothing. That begged the question: where did our data go???&lt;/p&gt;

&lt;p&gt;To illustrate our framework:&lt;br&gt;
Our parent App component holds the routing to our Library, Pokédex, and Pokémon Page components. In App, we fetch the data from the API in a &lt;a href="https://reactjs.org/docs/hooks-effect.html"&gt;useEffect&lt;/a&gt; hook and store that data in state. We then pass this data to all three child components as &lt;a href="https://www.w3schools.com/react/react_props.asp"&gt;props&lt;/a&gt; so it's available to render data in those components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="c1"&gt;//fetched data&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NavBar&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;HomePage&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/library"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Library&lt;/span&gt;
            &lt;span class="na"&gt;pokemons&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pokemons&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;//passing props to Library&lt;/span&gt;
          &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/pokedex"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Pokedex&lt;/span&gt;
            &lt;span class="na"&gt;pokemons&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pokemons&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;//passing props to Pokedex&lt;/span&gt;
          &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/:name"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PokemonPage&lt;/span&gt; 
            &lt;span class="na"&gt;pokemons&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pokemons&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;//passing props to PokemonPage&lt;/span&gt;
          &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What's funny is when we manually type in the URL for the Library and Pokédex components, they load as expected. It's only when we manually type in the URL for a specific Pokémon that the Pokémon Page renders nothing.&lt;/p&gt;

&lt;p&gt;To troubleshoot, I set several debuggers in my parent and child components to try and follow the path the code was taking. I also placed a console log of the props in the Pokémon Page component to check if it was coming through (it wasn't) - as well as console logs in certain places to see what lines of code were hitting. That's when I noticed something interesting.&lt;/p&gt;

&lt;p&gt;Important background info:&lt;br&gt;
When we initially fetch the data in the App component, we have it so there are two fetches happening asynchronously. This was necessary because of how the API is set up. The first fetch only provides the Pokémon names, so we use a second fetch to iterate through the names to get each Pokémon's details. Because the first fetch needs to finish before the second fetch can start, we leveraged &lt;a href="https://www.w3schools.com/js/js_async.asp"&gt;async and await&lt;/a&gt; to accomplish this. This caused state to be set continuously, making our code go back and forth between rendering our App and Pokémon Page components so that Pokémon Page would only load chunks of data at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getPokemons&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;pokeAPI&lt;/span&gt; &lt;span class="nx"&gt;url&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createPokemonObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&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;results&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="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;pokemon&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;pokeAPI&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="nx"&gt;by&lt;/span&gt; &lt;span class="nx"&gt;pokemon&lt;/span&gt; &lt;span class="nx"&gt;name&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&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="nx"&gt;setPokemons&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pokemons&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;pokemons&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;createPokemonObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&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;getPokemons&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;span class="c1"&gt;//returned JSX&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason this stifled the Pokémon Page component is because the delay in fetching led the component to first load with empty props. &lt;strong&gt;This prevented our image elements from rendering due to undefined sources (which would've come from the props) and in turn stopped our component from rendering altogether.&lt;/strong&gt; Even though &lt;em&gt;we&lt;/em&gt; know the data will technically be sent later, the component doesn't. So it doesn't try to re-render the component after it thinks it failed the first time.&lt;/p&gt;

&lt;p&gt;The solution I came up with to resolve this was to apply an if statement that wraps our JSX to return a different JSX (i.e. 'Loading...' text) if props are undefined, else return our original detailed page JSX. This allowed the page to continue attempting to render the asynchronously fetched data by tricking the component into thinking it's not failing anything so keep trying.&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pokemon&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&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="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;Loading&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;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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="c1"&gt;//JSX for the detailed page&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;



</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Cocktail Library {vanilla JS}</title>
      <dc:creator>Allison Kim</dc:creator>
      <pubDate>Wed, 10 Aug 2022 21:34:00 +0000</pubDate>
      <link>https://dev.to/allisonkim/cocktail-library-vanilla-js-5469</link>
      <guid>https://dev.to/allisonkim/cocktail-library-vanilla-js-5469</guid>
      <description>&lt;p&gt;Related to my previous post - here is a link to a project I completed for school that helped me gain milestones in understanding vanilla JavaScript:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://akimsahn.github.io/Phase-1-Project/"&gt;https://akimsahn.github.io/Phase-1-Project/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;How it works:&lt;/u&gt;&lt;br&gt;
This site functions as a one-stop database for all the different kinds of cocktails, with further info on their ingredients and how to make them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can filter the cocktails by specific ingredient or type of alcohol by selecting it from the dropdown menu&lt;/li&gt;
&lt;li&gt;You can select an image of a cocktail to display its details, including the list of ingredients and recipe instructions.&lt;/li&gt;
&lt;li&gt;You can add a rating and/or comment on the cocktail for personal documentation. (Ratings &amp;amp; comments will not persist between refreshes but will persist between selecting other cocktails.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;All interactivity on this site was set up using event listeners and pure vanilla JavaScript, as well as some CSS.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hope you enjoy! It's 5 o'clock somewhere, amirite?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Credit to &lt;a href="https://www.thecocktaildb.com/api.php"&gt;https://www.thecocktaildb.com/api.php&lt;/a&gt; for the API for fetching this data.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>First blog post...ever {object pointers}</title>
      <dc:creator>Allison Kim</dc:creator>
      <pubDate>Fri, 05 Aug 2022 17:49:00 +0000</pubDate>
      <link>https://dev.to/allisonkim/first-blog-postever-20p1</link>
      <guid>https://dev.to/allisonkim/first-blog-postever-20p1</guid>
      <description>&lt;p&gt;Hello! Warm welcome to my very first blog post as an aspiring software developer - where I'm currently learning to code at the Flatiron School. I aim to use this blog to track my growth and progress in the coding world.&lt;/p&gt;

&lt;p&gt;Full disclosure: I probably know about as much of coding as a brand-new driver knows what's under the hood of her car. I simply know how to get from point A to point B -- make the code do what I want it to -- but nothing on how to make the car use gas more efficiently or what parts it's even using at all.&lt;/p&gt;

&lt;p&gt;To get an idea of where I'm at, one thing I realized most recently - that was a big stepping stone for me - is the ability to assign a variable to an already-defined object (as a pointer) in order to make modifications to said object in a different scope.&lt;/p&gt;

&lt;p&gt;To illustrate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; &lt;span class="cm"&gt;/* first, globally defining an empty object to
be used later */&lt;/span&gt;

&lt;span class="cm"&gt;/* The "parent function" that defines an object in it's own
scope and calls the function passed in as an argument to modify
said object */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;parentFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;functionName&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;dataObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;key1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I want to change this value.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;key2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I want to keep this value.&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;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dataObj&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* re-assigning (or pointing) our empty
object to the defined object */&lt;/span&gt;

    &lt;span class="nx"&gt;functionName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* calling the callback function and
passing our variable to be updated */&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataObj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* this is just to see what's in our
defined object after the callback function's been called */&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//Callback function that changes a value of an object&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;callbackFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This value has been changed.&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;parentFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callbackFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//invoking the parent function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, in our console log, we'll see our defined-object has been updated to:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;key1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;This value has been changed.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;key2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I want to keep this value.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: the argument that was passed into the callback function was the &lt;code&gt;variable&lt;/code&gt; variable and not the actual &lt;code&gt;dataObj&lt;/code&gt;. Yet the changes persisted on the &lt;code&gt;dataObj&lt;/code&gt;, because &lt;code&gt;variable&lt;/code&gt; acts as a &lt;strong&gt;pointer&lt;/strong&gt; instead of a separate object. This was a breakthrough for me as the thought came to my head as I was trying to fall asleep one random night. Hope it can be of use to any new developers that come across this!&lt;/p&gt;

&lt;p&gt;Also, quick note on another trick I learned:&lt;br&gt;
To replace the &lt;code&gt;space&lt;/code&gt; character in a string with another character, simply use:&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;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;add character you want to replace with&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for reading!&lt;/p&gt;

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