<?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 Ky Capstick on Medium]]></title>
        <description><![CDATA[Stories by Ky Capstick on Medium]]></description>
        <link>https://medium.com/@kweenofcode?source=rss-fb8bdfffb827------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5lFG3fX9dNy1w1JvbLFWfw.jpeg</url>
            <title>Stories by Ky Capstick on Medium</title>
            <link>https://medium.com/@kweenofcode?source=rss-fb8bdfffb827------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:05:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kweenofcode/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[How to Upload Users’ Files to Firebase Storage for your React Application]]></title>
            <link>https://medium.com/@kweenofcode/how-to-upload-users-files-to-firebase-storage-for-your-react-application-34d729cbac1d?source=rss-fb8bdfffb827------2</link>
            <guid isPermaLink="false">https://medium.com/p/34d729cbac1d</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ky Capstick]]></dc:creator>
            <pubDate>Sun, 03 Jun 2018 00:59:15 GMT</pubDate>
            <atom:updated>2018-06-03T13:04:19.875Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*9M_Q0ddNOHwfC8wt6hPW5g.png" /></figure><p>If you’re reading this, I’ll assume you’ve already dabbled a bit in Google’s Firebase, and I will by-pass the steps about setting up Firebase in your React Application.</p><p><strong>SET UP FIREBASE STORAGE</strong></p><p>First, head over to your Firebase account and open the console for the project to which you’d like to add storage. Once there, click on the storage button located in the develop section of the sidebar. Firebase will display a pop-up asking you to “get started” and then issue a warning about the security of your storage (I’ll be ignoring that for my purposes)</p><p><strong>ADD INPUT TYPE=FILE</strong></p><p>In your render method you’ll want to add an input with a type of file with a <strong>ref</strong> attribute. The ref attribute allows you to access this DOM element within your React application. We’ll pass it a value as a callback function so we can access the uploaded file when the user selects it from their computer. It might look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*7Jcr8jQsl6AqB664PkiNCg.png" /><figcaption>we’ll define setRef in a moment</figcaption></figure><p>You would then define <strong>this.setRef</strong> in your constructor as such <em>(for an overview of why this is a best practice, check out </em><a href="https://hackernoon.com/refs-in-react-all-you-need-to-know-fb9c9e2aeb81"><em>Ankit Singh’s Hackernoon Article</em></a><em>)</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*bx7Hu2V-07okfqyJnPfNIw.png" /><figcaption>we re-assign the value of “ref” as “this.file”</figcaption></figure><p><strong>ADD AN UPLOAD BUTTON</strong></p><p>You’ll need a button to upload this file to Firebase and returns a specific URL referencing the file’s location. This button should have an <strong>onClick </strong>event<em> (make sure you bind it)</em> that does the following:</p><ol><li>Define the relative path of the uploaded file. Once a file has been selected, I can access the path of that file using the <strong>ref</strong> I set above.<em> this.file</em> becomes a reference to the file input DOM element and has a property called “files” which contains an array calls FileList. Our uploaded file is the first item in that array. So we store this in a variable as such:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*csmKKTzHXNoY9QNuMe9Afg.png" /><figcaption>as you’ll recall, I used this.file to define my ref attribute above</figcaption></figure><p>2. Then we create a variable to hold the reference to our Firebase Storage:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*hHsxjRwi3WKUiHU_bQpTMw.png" /><figcaption>a reference to firebase storage</figcaption></figure><p>3. Then we create a “child” element in our storage with the name of the uploaded file where we can store store the file itself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*An1zAZzWCIngWmweFUd6Yw.png" /><figcaption>creating a child in firebase storage named after the uploaded file</figcaption></figure><p>4. Now we put the details of the uploaded file inside this child element named after the uploaded file and retrieve the location of that image within our database:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*rVfc-PkV2z9cWbBZM8Kjbg.png" /><figcaption>using the Firebase “put” method to pass the file into the created child element and returning the “url”</figcaption></figure><p>Now that we have the download URL of the file you can store it as a state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*14qvTFt06NGpE3QFCGL_1w.png" /><figcaption>in my case, I was using it as an avatar</figcaption></figure><p>That’s it! Now you can upload and store users’ files or images in Firebase whenever you need!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34d729cbac1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Pass Values Between Sibling Pages Rendered Using React Router]]></title>
            <link>https://medium.com/@kweenofcode/how-to-pass-props-between-pages-rendered-using-react-router-2d1018bead15?source=rss-fb8bdfffb827------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d1018bead15</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-router]]></category>
            <dc:creator><![CDATA[Ky Capstick]]></dc:creator>
            <pubDate>Sat, 26 May 2018 20:56:49 GMT</pubDate>
            <atom:updated>2018-05-26T22:55:08.037Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Sy8jkjdlRMCZMVCVNHJFQ.jpeg" /></figure><p>Any stranger watching me try to puzzle my way through this question likely thought I was a vigilante investigator on the hunt for a serial killer in a crime thriller. I was displaying all the classic behavior: the angry, under-the-breath cursing, the eyes red from sleep deprivation, and the incomprehensible flow-charts scribbled and crossed out on every page of my notebook. I didn’t ask for this trouble. All I wanted was to pass the value(s) from a set of checkboxes representing dietary restrictions and allergies on the landing page of a web application to the page where the application makes a call to the Yummly Recipe API.</p><p><strong>STEP ONE: Gathering The Facts <em>(or, getting the value to be passed)</em></strong></p><p>First, I defined each of the dietary restrictions I could potentially pass to the Yummly API as objects within an array called diet in my component’s state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*o9EKjgYIxpX0V-BGgRuX3A.png" /><figcaption><em>the facts as they had been relayed to me</em></figcaption></figure><p><strong>STEP TWO: Setting The Trap <em>(or, gathering the user input)</em></strong></p><p>Once I had these options saved as states within my component I rendered each of them as a checkbox to the page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*5IyWgNteRSlc9h9qNNdr6A.png" /></figure><p>The onChange listener is passed a callback function so that when the checkbox is either checked or unchecked it will call the handleChange() function and pass the name of that specific dietary restriction as a parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*vCcqw9bW5Foj18onKSFsRQ.png" /></figure><p>Each time a checkbox is checked or unchecked, it will call this function that makes a copy of the current diet array of dietary restrictions objects, and gets the index of the dietary restriction corresponding to the checkbox that has been either checked or unchecked. The “isChecked” value of this dietary restriction object is updated to either true or false, depending on whether the box was checked or unchecked.</p><p><strong>STEP THREE: Setting Up Surveillance <em>(or, passing the prop from child to parent)</em></strong></p><p>Now that I had the state of the LandingPage updating each time a box is checked or unchecked, I needed to pass the selected dietary restrictions to the page where the call to the Yummly API was being made. Before I do this, let’s review how the application is set up. First, let’s take a look at our app.js file where we’ve set up our React Router:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*5_BvebftxmVwS0tTc8VQrQ.png" /><figcaption>where we want to chase the trapped value</figcaption></figure><p>The only logical path from the LandingPage where the user is inputting their dietary restrictions to the Recipes.js page where the call for recipes is being made is through the app.js file where they are both being rendered by the React Router (for a more detailed look at how to pass props between related components outside of the React Router, check out Ruth M. Pardee’s Medium article <a href="https://medium.com/@ruthmpardee/passing-data-between-react-components-103ad82ebd17">here</a>).</p><p>Before we can pass the dietary restriction value to the Recipes component, we need to pass it from the Landing component to the app.js, which means passing from child to parent. We do this in two steps:</p><p><strong><em>FIRST:</em></strong></p><p>We using React Router’s built-in render prop to pass a callback function as a prop to our LandingPage component. (for a good explanation of how the render prop works, check out Tyler McGinnis’s article <a href="https://tylermcginnis.com/react-router-pass-props-to-components/">here</a>). For our purposes, this looks something like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*s1Nt4u5p0_37Sg2At02cNw.png" /><figcaption>the location of the final showdown</figcaption></figure><p><strong><em>SECOND:</em></strong></p><p>Now in our LandingPage component we create an array to store the values of all the checked boxes, and then pass these values as an argument through this dietCallback() function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*egyeATUiyr-_QpQ_polvVQ.png" /></figure><p>First, I iterate through the objects in the diet array, and if they have an isChecked value of true, I push them into a new array called checkedItems. Because I need to pass these values as a string, I use the .join( ) method to transform this array of checked boxes into a string of comma separated values. At this point, I call the dietCallback() function that had been passed down as a props from app.js and pass this newly made string as an argument. Now, I can access the value in our app.js file. If you remember from above, we had passed the getDiet() function as the prop for the Landing Component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*OQAoWeJPCfwIHpOTsEu70A.png" /></figure><p><strong>STEP FOUR: Springing The Trap <em>(or, passing the prop from parent to child)</em></strong></p><p>Now, when we check a box on the LandingPage, it will pass that value as the argument of a callback function to the app.js component. We access this value within this function and set it as a state on this component. Now that we have it stored as a state in app.js, we can pass it as a props to our Recipes component. Again, we do this using the render prop of the React Router, and pass our Component callback function props from app.js:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*FqmgJcKJbbxKyUfVttrWLA.png" /></figure><p>Now, we can pass the value of diet the way we would normally pass a prop from parent to child by setting the diet prop as a state in our Recipes.js component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*Vzd5Q-VE1TTFR5M9XanDsw.png" /></figure><p>And just like that, we’ve passed a value from one page to another using React Router. Now we’re able to access the user’s choice in our API calls, so we can accurately filter recipes based on user’s dietary restrictions. The case is solved and maybe I can finally pull all those red pins out of my bedroom’s wall.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d1018bead15" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>