<?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 Amanda Correa on Medium]]></title>
        <description><![CDATA[Stories by Amanda Correa on Medium]]></description>
        <link>https://medium.com/@amagonzalez27?source=rss-86ecdf9bd836------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zyTEWFNk4vQ9gw62U4A36A.jpeg</url>
            <title>Stories by Amanda Correa on Medium</title>
            <link>https://medium.com/@amagonzalez27?source=rss-86ecdf9bd836------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:59:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amagonzalez27/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[Hello World: Firebase-Realtime Database]]></title>
            <link>https://medium.com/@amagonzalez27/hello-world-firebase-realtime-database-abf28fe264ef?source=rss-86ecdf9bd836------2</link>
            <guid isPermaLink="false">https://medium.com/p/abf28fe264ef</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[realtime-database]]></category>
            <category><![CDATA[firebaserealtimedatabase]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Amanda Correa]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 20:33:19 GMT</pubDate>
            <atom:updated>2019-01-27T20:33:19.881Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BatQglJxsUVGYcnC" /><figcaption>Photo by <a href="https://unsplash.com/@mpho_mojapelo?utm_source=medium&amp;utm_medium=referral">Mpho Mojapelo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This tutorial will cover a basic hello_world app interacting strictly with Firebase Realtime database and React. Then we will dive a little deeper on whats happening behind the scenes.</p><p><strong>Prerequisite:</strong></p><p>I’ll assume that you are familiar with React and setting up your own application using create-react-app and knowledgeable in NoSQL databases.</p><h3><strong>Step 1:</strong></h3><ul><li>Create a project at <a href="https://console.firebase.google.com/">https://console.firebase.google.com/</a></li><li>Create a React application using “create-react-app”</li><li>cd into our React app and npm start!</li></ul><p>The following images will demo where to find your configurations.</p><p>You’ll want to locate the Project settings at the top of the menu bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*la-5U8WrPRE1WptLRLMbbw.png" /></figure><p>Once you’ve done that, you’ll be able to see a view of your general settings. Click on the “Web” platform to view your configs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mdFA6ROyFJ84xtLRQX15Tg.png" /><figcaption>We are creating a Web application</figcaption></figure><p>Copy your configurations without the script tags. This will be placed in our React app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ov5JQrGQs0QYn3tpRM_ASg.png" /><figcaption>Configurations</figcaption></figure><h3>Step 2:</h3><ul><li>Install firebase</li><li>Add configurations</li></ul><pre>npm install firebase</pre><ul><li>Create a firebase_config.js file within our src folder</li></ul><pre>// firebase_config.js </pre><pre>import firebase from &#39;firebase&#39;</pre><pre>const config = {<br>  apiKey: &quot;hell_world_api_key&quot;,<br>  authDomain: &quot;hello-world-app.firebaseapp.com&quot;,<br>  databaseURL: &quot;https://hello-world-app.firebaseio.com&quot;,<br>  projectId: &quot;hello-world-app&quot;, <br>  storageBucket: &quot;simple-firebase-app-32b0d.appspot.com&quot;,<br>  messagingSenderId: &quot;00000000000000000&quot;<br>}</pre><pre>export const database = firebase.database();</pre><blockquote>Note: Never commit your configurations to Github!! You would usually store these in a .env file but we will keep them here for the sake of this tutorial.</blockquote><h3>Step 3:</h3><ul><li>Import the firebase database from your config file</li><li>Render something beautiful!</li></ul><pre>// App.js</pre><pre>import React, {Component} from &#39;react&#39;<br>import &#39;./App.css&#39;<br>import {database} from &#39;./firebase_config&#39;</pre><pre>class App extends Component {<br>  constructor(props) {<br>    <em>super</em>(props);<br>    <em>this</em>.state = {<br>      title: &#39;&#39;,<br>      body: &#39;&#39;,<br>      ideas: [],<br>    };<br>  }</pre><pre>  handleSubmit(e) {<br>    e.preventDefault();<br>    //TODO: send my ideas to the database!!<br>  }</pre><pre>  handleChange(e) {<br>   // Update state with the input changes<br>   this.setState({[e.target.name]: e.target.value});<br>  }</pre><pre>  render() {<br>    return({<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;h1&gt;Hello World&lt;/h1&gt;<br>        &lt;h3&gt;Add your great ideas here!&lt;h3&gt;<br>        &lt;div&gt;<br>          &lt;form onSubmit={this.handleSubmit.bind(this)}&gt;<br>            &lt;input<br>              label=&quot;Title&quot;<br>              name=&quot;title&quot;<br>              type=&quot;text&quot;<br>              value={this.state.title}<br>              onChange={this.handleChange.bind(this)}<br>              placeholder={&#39;Whats the name of your idea?&quot;}<br>            /&gt;<br>            &lt;input<br>              label=&quot;Body&quot;<br>              name=&quot;body&quot;<br>              type=&quot;text&quot;<br>              value={this.state.body}<br>              onChange={this.handleChange.bind(this)}<br>              placeholder={&#39;Whats the name of your idea?&quot;}<br>            /&gt;<br>           &lt;button type=&quot;submit&quot;&gt;Save&lt;/button&gt;<br>          &lt;/form&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    })<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*JIoUsQrQrXFMF0Wj9VD2xw.png" /><figcaption>Ta Da!!!</figcaption></figure><blockquote><strong>Now down to the good stuff!!</strong></blockquote><h3>Step 4:</h3><ul><li>Add a handleSubmit function that will add/render our new ideas to the firebase database and persist them for later.</li><li>Have an option where we can delete our ideas from the database and from our current state.</li></ul><pre>// App.js</pre><pre>...</pre><pre>class App extenders Component {<br>   ... <br>  <br>  componentDidMount() {<br>    const results = database.ref(&#39;ideas/&#39;).on(&#39;value&#39;, data =&gt; {<br>      if(data.val() !== null) {<br>        let obj = data.val();<br>        let ideas = Object.keys(obj).map(key =&gt; {<br>          return {<br>            id: key,<br>            title: obj[key].title<br>            body: obj[key].body<br>          }<br>        });</pre><pre>        this.setState({ideas});</pre><pre>       }<br>     });<br>    }<br>  <br>  handleSubmit(e) {<br>   ...<br>   const {title, body} = this.state;<br>  <br>   database.ref(&#39;ideas/&#39;)<br>   .push()<br>   .set({<br>     title,<br>     body,<br>   });</pre><pre>  handleChange(){...}</pre><pre>  renderIdeas() {<br>    return this.state.ideas.map((value, key) =&gt; {<br>      return (<br>        &lt;div<br>          key={key}<br>          style={{<br>            margin: 10,<br>            border: &#39;1px solid black&#39;,<br>            width: &#39;50%&#39;<br>          }}&gt;<br>          &lt;h3&gt;{value.title}&lt;/h3&gt;<br>          &lt;p&gt;{value.body}&lt;/p&gt;<br>          &lt;button<br>            onClick={() =&gt; {<br>              this.deletePost(value.id);<br>            }}<br>          &gt;<br>            Delete<br>          &lt;/button&gt;<br>        &lt;/div&gt;<br>        );<br>     }):<br>  }</pre><pre><br>  deleteIdea(id) {<br>   // filter through current state and remove deleted idea</pre><pre>    const ideas = this.state.ideas.filter(idea =&gt; idea.id !== id);<br>    this.setState({ideas});<br>    <br>    // Remove it from the database as well</pre><pre>    database.<br>      ref(&#39;ideas/&#39;)<br>      .child(id)<br>      .remove();<br>   }</pre><pre>  render() {<br>    return (<br>      &lt;div&gt;</pre><pre>      ...</pre><pre>        &lt;div<br>          style={{<br>            display: &#39;flex&#39;,<br>            flexDirection: &#39;column&#39;,<br>            justifyContent: &#39;center&#39;,<br>            alignItems: &#39;center&#39;,<br>          }}<br>          &gt;<br>          {<em>this</em>.renderPosts()}<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>     );<br>   }<br>}</pre><p><strong>What just happened?</strong></p><ul><li>In the componentDidMount we are telling firebase to get all the data referencing the ‘ideas/’ node. The .on() method listens to any changes on the database. The response is an object. Therefore, we might want to convert the given object to an array so that we could update the current <em>ideas</em> state. <em>Note that we could have also changed our ideas array into an object instead</em>.</li><li>Now, in the handleSubmit() we make a reference to the ‘ideas/’ node where we’ll notice the .push(); (this generates a new ID for the given child). The .set() adds an object with given data to the database.</li></ul><blockquote>Note: .set() can also be used to update your database</blockquote><ul><li>Finally, if we ever want to delete data from the database, it is super easy! On the deleteIdea() function we want to make a reference to the correct child ID and then call .remove().</li></ul><h3>Step 5:</h3><ul><li>Watch the magic happen on Firebase!!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RDpB0cBCF0720mkM7E0fUg.gif" /><figcaption>Here is what you came for!!!</figcaption></figure><h3>Conclusion</h3><p>Firebase is a NoSQL database. Here we used Firebase Realtime Database where it displays our data as a json object. Some other features you could check out on Firebase are authentication, storage, hosting, functions, and the machine learning kit.</p><p><em>Check out </em><a href="https://howtofirebase.com/@ChrisEsplin"><em>Chris Esplin</em></a><em>’s medium for some great firebase related content and his stories on “How To Firebase”!</em></p><p><em>For some in depth reading always check the docs at </em><a href="https://firebase.google.com/docs/guides/"><em>Firebase</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abf28fe264ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>