<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by William Gotterer on Medium]]></title>
        <description><![CDATA[Stories by William Gotterer on Medium]]></description>
        <link>https://medium.com/@william.gotterer?source=rss-ee97cb11d5be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OM1kqn0DDEcBp2nW</url>
            <title>Stories by William Gotterer on Medium</title>
            <link>https://medium.com/@william.gotterer?source=rss-ee97cb11d5be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:55:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@william.gotterer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Passing Props And The Power Of The Callback In React: A Bedtime Story]]></title>
            <link>https://medium.com/@william.gotterer/passing-props-and-the-power-of-the-callback-in-react-a-bedtime-story-c193c7ef9f7a?source=rss-ee97cb11d5be------2</link>
            <guid isPermaLink="false">https://medium.com/p/c193c7ef9f7a</guid>
            <category><![CDATA[props]]></category>
            <category><![CDATA[props-and-state]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[jsx]]></category>
            <dc:creator><![CDATA[William Gotterer]]></dc:creator>
            <pubDate>Wed, 27 Oct 2021 20:42:26 GMT</pubDate>
            <atom:updated>2021-10-29T12:41:16.200Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5TEgYh8qT6Uo8hiPE1pGw.png" /></figure><p>Many moons ago, in the not so distant future, lived the most powerful dragon to fly over this land. However, there was a time before this imminent future in which The Dragon Queen was becoming old and fragile, hardly able to cough out a puff of smoke from her horrendously chapped mouth. This all changed when, one day, her trusted servant, Hasty Hog, mentioned the whereabouts of some underground fungi that could restore her health. The Dragon Queen sent Hasty Hog on a quest to sniff out these fungi, gather all he could, and return back to her as fast as his little wings could flap.</p><h4>Passing down props in React from a parent component to a child component and then invoking a callback in the child…</h4><p>is an incredibly powerful tool that allows one to send information from a child component back to a parent component so it can utilize the information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DL4UalAq3JJgLuPljQD_xw.png" /></figure><p>Delving into the code we can see that DragonQueen is our parent component and HastyHog is its child. In the DragonQueen component we are setting two states for queenPowers and queenFirePower. In the return statement we have two divs in which the two states will render a number depending on what the state is set to. Initially The Dragon Queen is very weak and when looking at the browser picture above, one can see her omnipotence is equal to 2 out of 9 (9 being the strongest) and her fire power is equal to 3 out of 9. She is tired of being decrepit and thus sends Hasty Hog off on his quest with some information. That information being what The Dragon Queen wants changed. In her case she wants her omnipotence and power to increase. In other words, The Dragon Queen wants to update the state of queenPowers and queenFirePower to a higher number. This information is crucial for Hasty Pig to know as it would be a disaster if he came back with some fungi that, for example, gave her food poisoning! We can be assured Hasty Pig will know what fungi to gather as the two functions handling state, handleOmnipotence and handleFirePower, are passed down as props to the HastyHog child component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6Hff2wyQCjQkF4z6i0vvg.png" /></figure><p>In the HastyHog component, in order for the Hasty Hog to keep ahold of what he needs to do, the “handle” functions need to be passed down as parameters. Let’s now dive snout first into our return statement where Hasty Pig will actually be gathering the mystical fungi. We have two inputs that can hold a number value. Hasty Hog gathers the powerful mushrooms for The Dragon Queen and needs to find his way home. How is that possible?!?! The route home is provided to us by the call-back function with a parameter of “e.target.value” inside the Onchange event. The call-back function is the key to having Hasty Hog return and restoring The Dragon Queen’s powers. Let’s take a closer look at what is happening in the call-back functions’ parameters. Each function is taking the value, whatever number is typed in, of the input field. If we then scroll up to our picture of the DragonQueen (parent) component we can see that both of our functions have parameters, or place holders. One being omnipresentPowerFromHogQuest and the other firePowerFromHogQuest. These again are just place holders for what is being passed up from the child component. In this example the two place holders become the “e.target.value” being passed up by HastyHog’s callback functions. At this point The Dragon Queen has her powerful fungi and due to the “e.target.value” being set to state in her component the numbers update and she regains her powers!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FpZvYMk_O1_U%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpZvYMk_O1_U&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FpZvYMk_O1_U%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb4f9ad32550e021a9acdb6f798ff528/href">https://medium.com/media/cb4f9ad32550e021a9acdb6f798ff528/href</a></iframe><p>Image resources… <a href="https://www.phrases.org.uk/meanings/pigs-might-fly.html">https://www.phrases.org.uk/meanings/pigs-might-fly.html</a> and <a href="https://www.spiritanimal.info/dragon-spirit-animal/">https://www.spiritanimal.info/dragon-spirit-animal/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c193c7ef9f7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner’s guide to JavaScript’s map()]]></title>
            <link>https://medium.com/@william.gotterer/beginners-guide-to-javascript-s-map-895b004fecad?source=rss-ee97cb11d5be------2</link>
            <guid isPermaLink="false">https://medium.com/p/895b004fecad</guid>
            <category><![CDATA[spongebob]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[begginer]]></category>
            <category><![CDATA[functions-in-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[William Gotterer]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 13:26:06 GMT</pubDate>
            <atom:updated>2021-10-06T20:43:41.484Z</atom:updated>
            <content:encoded><![CDATA[<p>What is a map() function and how do we use it? Let’s use a Spongebob analogy to unpack what it does.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FUnb-CfNx4KQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DUnb-CfNx4KQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FUnb-CfNx4KQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb86239be9751cfcc998964ff8ffd0de/href">https://medium.com/media/bb86239be9751cfcc998964ff8ffd0de/href</a></iframe><p>In this episode, Spongebob, Patrick, and Mr. Krabs go on an adventure to find the Dutchman’s treasure. The three rely on a map to get to their destination. This is a good start. A regular map outlines the terrain of the real world, gives us a copy of the features that exist, and we can arrive at different end points depending on the path we take. Our map() function takes on similar characteristics, hence, “map”().</p><p>W3schools defines a map() as</p><blockquote>— a <em>method that creates a new array with the results of calling a function for every array element</em></blockquote><blockquote><em>— a </em>method calls the provided function once for each element in an array, in order.</blockquote><blockquote>— a method that does not change the original array.</blockquote><p>Let’s delve into what this means using an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*h6FHvgxOBp7d6qIDyjsCOg.png" /></figure><p>In the above example we have an array, “numOfKrabbyPatties”, that shows the amount of Krabby Patties we can imagine Mr. Krabs, Spongebob, and Patrick having at the beginning of their treasure hunt. Next, the variable, “leftoverPattiesArr”, is created to represent what happens to the Krabby Patties of each character after a certain amount of time. In this case 3 are eaten by each character.</p><p>If we take a look at the value of “leftoverPattiesArr” we can see that we are taking our “numOfKrabbyPatties” array and using the map() function on it. The map() function inherently calls on EACH item in the “numOfKrabbyPatties” array, but we need to tell it what we want it to do with the “numOfKrabbyPatties” array. This is where the function “hungryCharacters” play its role. It gives the map() some guidance. Just like our three characters traversing the ocean floor to find the “X” on the treasure map, our “hungryCharacters” function is similar in that it provides the trail the array must follow to get to its new end point.</p><p>Taking a closer look at our “hungryCharacters” function, one can notice that a parameter, “patties”, is set. Wrapping my head around what this parameter does was a little challenging at first. Alas, with the help of Spongebob and his friends, anything is possible! Remember that the function is called once for EVERY element in the array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*TqCh__qx45DN-7Hlf4OqEw.jpeg" /></figure><p>What is happing when we invoke “leftoverPattiesArr” is the map takes the first element in “numOfKrabbyPatties” and passes it through our function. In our case 12 Krabby Patties becomes the “patties” placeholders, and the subtraction (12–3) is performed. Again, the inherent property of the map() is to now take the second element of “numOfKrabbyPatties” and follow the same path. The second element is 6, therefore as it moves through the function it, for the time being, replaces the “patties” placeholders. Thus performing (6–3). The same process repeats for the last element in our array as well. Finally, we have a non-destructive process that keeps our old array, “numOfKrabbyPatties”, in tact while providing us with a new, manipulated array, “leftoverPattiesArr”.</p><p>As we navigate with our map, what gets altered is how we exist within that terrain. We are, in other words, making changes to our relationship with our map. One minute we are at point “a” and some time later we are at point “b”. Similarly, in our example the Krabby Patties are being manipulated as they move through their map() terrain. At the so called beginning, point “a”, of the map() they are one way and by the end, point “b”, another.</p><h3><strong>Let’s dig a little deeper!</strong></h3><p>We don’t always deal with arrays that are that simple. Let’s take a look at one with some objects inside. If you aren’t familiar with the Spongebob episode being referred to throughout this article, you should know that the three get into a small quarrel regarding the treasure after it’s found. Their commotion wakes the ghost of The Flying Dutchman and he is subsequently angry. For the purpose of this example, let’s say that he takes back his treasure chest and gives each of our characters 1 gold coin.</p><p>We want to express this by creating sentences with the new information we have. Below you will see “characters”, an array of 3 objects containing 2 key:value pairs. Our function “getTreasure” will be invoked for every object in our array. In this case 3. Similarly to our previous example, the parameter, “oneCharacter”, is a place holder for each entire object. For example, the first iteration would take {name : “Mr. Krabs”, treasure: 0} and pass it in as the new temporary placeholder. At this point, between the curly braces “{}”, is where we say what we want to do with this object. In this function we are saying we want ${oneCharacter.name}. “OneCharacter” being the placeholder for each object iteration within the array. We then want to grab the value of “name” to begin our sentence. This is interpolated using back-ticks at the beginning and end of the return statement. Then putting our variables between ${}. This allows us to incorporate stringed elements such as “has” and “piece of gold!”. We interpolate a second time using ${oneCharacter.treasure + 1}. Just like the previous interpolation, our “OneCharacter” is the placeholder for each iteration over the objects. We then grab ahold of the “treasure” key in order to get its value. Finally we add 1 to the value. As a final result one can see that characters.map(getTreasure) gives us a new array of three different strings! Remember, our initial array of “characters” was not changed because map() is non-destructive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAz776nN1B6t7wIF7pobKQ.png" /></figure><p>References:</p><p><a href="https://www.w3schools.com/jsref/jsref_map.asp">https://www.w3schools.com/jsref/jsref_map.asp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=895b004fecad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>