{"id":1179,"date":"2020-06-18T07:13:38","date_gmt":"2020-06-18T07:13:38","guid":{"rendered":"https:\/\/weichie.com\/react-firebase-chat-app-part-2\/"},"modified":"2024-02-05T15:42:49","modified_gmt":"2024-02-05T15:42:49","slug":"react-firebase-chat-app-part-2","status":"publish","type":"post","link":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/","title":{"rendered":"Een React Chat-app maken met Firebase, React Router &#038; Authenticatie (deel 2)"},"content":{"rendered":"<div class=\"default__block container-fluid lg\">\n<p>This post will continue to finish the actual chat part on top of our previous <a href=\"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app\/\">React Firebase setup from part 1<\/a>. But it&#8217;s finally here!<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Our firebase chat app will use the real-time database from Firebase and not the Cloud Firestore. Why? Because the real-time database updates our app automatically for us, so we don&#8217;t need to do anything special to make it work!<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>You can find a working example of our app on chat.weichie.com (unavailable) and you can <a href=\"https:\/\/github.com\/weichie\/react-firebase-chat\" target=\"_blank\" rel=\"noreferrer noopener\">find the complete project on Github<\/a> as well.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/web-design-agency-brussels-03-1024x1024.jpg\" alt=\"React chat app with firebase mockup\" class=\"wp-image-2077\"\/><\/figure>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-where-did-we-left-our-react-chat-application-after-part-1\">Where did we left our React Chat application after part 1?<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>I created this app more than 2 years ago and in the meantime over 1000 people registered to test the chat app! Apologies to everyone who was waiting on part 2, but a recent comment on the Part 1 article made me realize that my blog has more traffic than I thought.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>So here we go! <strong>Feel free to refresh my mind in the comments if I am talking nonsense in this post<\/strong>. I am no longer using React for my applications but switched it for Vuejs instead.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-using-authentication-in-our-router\">Using authentication in our Router<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Only registered users will be able to post chat-messages in our application. Otherwise&#8230; We don&#8217;t know who said something. To make sure users are logged in, we&#8217;ll change our Router component like this:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ index.js\n...\n\n&lt;Router&gt;\n  &lt;div className=\"app\"&gt;\n    &lt;nav className=\"main-nav\"&gt;\n      {!this.state.user &amp;&amp; \n        &lt;div&gt;\n          &lt;Link to=\"\/login\"&gt;Login&lt;\/Link&gt;\n          &lt;Link to=\"\/register\"&gt;Register&lt;\/Link&gt;\n        &lt;\/div&gt;\n      }\n\n      {this.state.user &amp;&amp; \n        &lt;a href=\"#!\" onClick={this.logOutUser}&gt;Logout&lt;\/a&gt;\n      }\n    &lt;\/nav&gt;\n\n    &lt;Switch&gt;\n      &lt;Route path=\"\/\" exact render={() =&gt; &lt;Home user={this.state.user}\/&gt;} \/&gt;\n      &lt;Route path=\"\/login\" exact component={Login} \/&gt;\n      &lt;Route path=\"\/register\" exact component={Register} \/&gt;\n      &lt;Route component={NoMatch} \/&gt;\n    &lt;\/Switch&gt;\n  &lt;\/div&gt;\n&lt;\/Router&gt;\n\n...<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>We changed a few things in our index.js-file to check authenticated users. Let&#8217;s start with the navigation on top.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>We create a navigation element main-nav with 2 navigation elements. One that will be displayed when our user is logged in, and another navigation that will be displayed when the user is logged out. So he can choose if he wants to log in with an existing account or register a new account (and talk with himself)<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>The other important thing we changed in our index.js file is that we swapped the <code>{home}<\/code> component with a function, that renders our component in-line. This way we&#8217;re able to pass our logged in user as a prop to our home component.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-the-home-component\">The Home Component<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Our Home component is the home screen of our application. This screen will show you the chat-app when you are logged in, or the option to create your account if you are logged out.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p><strong>First the setup<\/strong>: Now that our router passes our user-state to our Home component, we can display authentication-based elements in this component as well. Let&#8217;s see what it looks like:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ Home.js\nimport React from 'react';\nimport {Link} from 'react-router-dom'; &lt;-- add this line\n\nclass Home extends React.Component{\n  render(){\n    return(\n      &lt;div className=\"home--container\"&gt;\n        &lt;h1&gt;Welcome to the chat!&lt;\/h1&gt;\n        {this.props.user &amp;&amp; \n          &lt;div className=\"allow-chat\"&gt;\n            We insert our chat-component later\n          &lt;\/div&gt;\n        }\n        {!this.props.user &amp;&amp; \n          &lt;div className=\"disallow-chat\"&gt;\n            &lt;p&gt;&lt;Link to=\"\/login\"&gt;Login&lt;\/Link&gt; or &lt;Link to=\"\/register\"&gt;Register&lt;\/Link&gt; to start chatting!&lt;\/p&gt;\n          &lt;\/div&gt;\n        }\n      &lt;\/div&gt;\n    );\n  }\n}\nexport default Home;<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>In our home render function, we added an if-statement to see whether or not our users are logged in. If so, we are allowed to show our chatbox. If not, we give them the option to log in or to create a new account.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Make sure to import <code>{Link}<\/code> at the top of our Home.js file.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-chatbox-js-where-the-magic-happens\">Chatbox.js &#8211; Where the magic happens<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>The most important file! Apologies again if some of you waited so long for me to finally finish up Part 2 as well&#8230; a sincere apology from my end!<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>So Let&#8217;s dive right in and create a Chatbox.js file inside our Home folder. To clarify, this is what our folder structure <strong>inside \/src\/ <\/strong>looks like:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<ul class=\"wp-block-list\"><div class=\"default__block container-fluid lg\">\n<li>\/components<div class=\"default__block container-fluid lg\">\n<ul class=\"wp-block-list\"><div class=\"default__block container-fluid lg\">\n<li>\/Auth<div class=\"default__block container-fluid lg\">\n<ul class=\"wp-block-list\"><div class=\"default__block container-fluid lg\">\n<li>Auth.css<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>Login.js<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>Register.js<\/li>\n<\/div><\/ul>\n<\/div><\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>\/Home<div class=\"default__block container-fluid lg\">\n<ul class=\"wp-block-list\"><div class=\"default__block container-fluid lg\">\n<li>Chatbox.js<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>Home.css<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>Home.js<\/li>\n<\/div><\/ul>\n<\/div><\/li>\n<\/div><\/ul>\n<\/div><\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>firebase.js<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>index.css<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li>index.js<\/li>\n<\/div><\/ul>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>And then we&#8217;ll add the usual defaults for a new component:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>import React from 'react';\n\nclass Chatbox extends React.Component{\n  render(){\n    return(\n      &lt;div className=\"chatbox\"&gt;\n        &lt;ul className='chat-list'&gt;\n          &lt;li&gt;Here we show our chat messages&lt;\/li&gt;\n        &lt;\/ul&gt;\n      &lt;\/div&gt;\n    );\n  }\n}\nexport default Chatbox;<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Nothing too crazy in here yet. Just a simple component that, for now, will return a list with 1 static element. Next: Add firebase! We will create a component-state into Chatbox.js where we will insert all the messages that we&#8217;re pulling from firebase. <\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>So what do we need? A <em>constructor<\/em> for our state that will store the firebase messages in our app. And a call to firebase to get all the messages in our application. This function will be run when our Chatbox component is mounted. Here&#8217;s the setup code:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ Chatbox.js\n...\nclass Chatbox extends React.Component{\n  constructor(props){\n    super(props);\n    this.state = {\n      chats: &#91;]\n    }\n  }\n\n  componentDidMount(){\n    console.log('Chatbox.js is mounted!');\n  }\n\n  render(){\n    ...\n  }\n}<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>We have a constructor with a state for our &#8216;chats&#8217; and if we can see &#8216;Chatbox.js is mounted!&#8217; in our console, we&#8217;re ready for the firebase integration. <\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>The Firebase Realtime Database works with &#8216;refs&#8217;. Although it returns one huge JSON tree, refs will give us easy access to the data we need. Our chat app is still empty at the moment, so we need to add some test messages first before we can display our chat list.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h3 class=\"wp-block-heading\" id=\"h-let-s-add-some-messages-back-to-our-home-component\">Let&#8217;s add some messages! Back to our Home Component<\/h3>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>To ease up development, it would also be nice if we could see our Chatbox component in our app. So let&#8217;s hook it up really quick:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ Home.js\nimport React from 'react';\n...\nimport Chatbox from '.\/Chatbox'; &lt;-- Add this line\n\n...\n  \/\/ Update our render method:\n  &lt;h1&gt;Welcome to the chat!&lt;\/h1&gt;\n  {this.props.user &amp;&amp; \n    &lt;div className=\"allow-chat\"&gt;\n      &lt;Chatbox \/&gt;\n    &lt;\/div&gt;\n  }\n...<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>This adds the Chatbox component when our user is logged in so we can see what we&#8217;re doing. Let&#8217;s continue:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>We can&#8217;t pull an empty list from Firebase. I mean&#8230; we can&#8230; but we won&#8217;t see anything. So head back to our Home.js component and we&#8217;ll write some logic to add messages to our database.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ Home.js\nimport React from 'react';\nimport firebase from '..\/..\/firebase'; &lt;-- Add this line\nimport {Link} from 'react-router-dom';\n\nclass Home extends React.Component{\n  constructor(props){\n    super(props);\n    this.state = {\n      message: ''\n    }\n  }\n\n  handleChange = e =&gt; {\n    this.setState({&#91;e.target.name]: e.target.value});\n  }\n\n  render() {\n    ...\n    &lt;div class=\"allow-chat\"&gt;\n      &lt;form className=\"send-chat\" onSubmit={this.handleSubmit}&gt;\n        &lt;input type=\"text\" name=\"message\" id=\"message\" value={this.state.message} onChange={this.handleChange} placeholder='Leave a message...' \/&gt;\n      &lt;\/form&gt;\n      \n      &lt;Chatbox \/&gt;\n    &lt;\/div&gt;\n    ...\n  }\n}\nexport default Home;<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>What&#8217;s happening? We created a state in our Home component and added a form in our &#8216;send-chat&#8217; div. In React\/Vue\/Angular\/&#8230; you are not allowed to have unbound forms. So our input-field has an onChange method that will keep the value in our input field in sync with the input field value in our state.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>I already made you import firebase at the top of our file and gave our chat-form the onSubmit function, because we&#8217;re continuing our send-message logic right away:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ Home.js\n...\nhandleSubmit = e =&gt; {\n  e.preventDefault();\n  if(this.state.message !== ''){\n    const chatRef = firebase.database().ref('test');\n    const chat = {\n      message: this.state.message,\n      user: this.props.user.displayName,\n      timestamp: new Date().getTime()\n    }\n\t\t\n    chatRef.push(chat);\n    this.setState({message: ''});\n  }\n}\n...<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>The handleSubmit function goes above our render() method. Like how we did the handleChange function. When submitting the form, we check if the message is empty. If so, we don&#8217;t do anything (otherwise people can push empty values to your database &#8211; talking from experience&#8230;)<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>If we have a value to push, we create a chatRef. This one will be a firebase database reference. Note that this can be anything we&#8217;d like. In my example I used &#8217;test&#8217; as ref, create a chat message object and push it to our chatRef. Then we also update our state, so the message field get cleared once the message is submitted.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>The &#8216;chat&#8217; object we&#8217;re pushing to firebase looks like this:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<ul class=\"wp-block-list\"><div class=\"default__block container-fluid lg\">\n<li><strong>message<\/strong>: Our state.message, the message that the user wrote<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li><strong>user<\/strong>: The username from the user. We passed our user as a prop to the Home component, so we can access it like this<\/li>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<li><strong>timestamp<\/strong>: A general javascript timestamp, to know when people are posting messages<\/li>\n<\/div><\/ul>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>When you hit submit, you should be able to see our &#8216;Test&#8217; ref and our message in the Realtime database! Booyaa.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/firebase-realtimedatabase-test.jpg\" alt=\"\" class=\"wp-image-2537\"\/><\/figure>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>If the test is working, you can change the ref in the <code>const chatRef = firebase.database().ref('test');<\/code> line from &#8217;test&#8217; to whatever you want. As you can see in the image, I&#8217;ll be using &#8216;general&#8217; in this example. But this can be anything you want &#8211; and you can change it on the fly! (if you want to make different chatrooms or something like that)<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-pulling-our-messages\">Pulling our messages<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>All righty, now that we are able to push data to our firebase database, we&#8217;re ready to pull them back into our app as well. Back in Chatbox.js we&#8217;ll complete our componentDidMount() function to pull our firebase data when our chatbox is loaded.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ Chatbox.js\nimport React from 'react';\nimport firebase from '..\/..\/firebase'; &lt;-- Add this line\n\nclass Chatbox extends React.Component{\n  ...\n\n  componentDidMount(){\n    const chatRef = firebase.database().ref('general');\n    chatRef.on('value', snapshot =&gt; {\n      const getChats = snapshot.val();\n      let ascChats = &#91;];\n      for(let chat in getChats){\n        ascChats.push({\n          id: chat,\n          message: getChats&#91;chat].message,\n          user: getChats&#91;chat].user,\n          date: getChats&#91;chat].timestamp\n        });\n      }\n      const chats = ascChats.reverse();\n      this.setState({chats});\n    });\n  }\n\n  render(){\n    ...\n  }\n}\nexport default Chatbox;<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Ok, sooo. On componentDidMount() we get the Chat reference we created previously in our Home component. Make sure to use the same reference as where you&#8217;re posting your messages to \ud83d\ude09 <\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>That&#8217;s actually <strong>all there is to do<\/strong>! If we have a chatRef, we take the snapshot and store it in a variable. The snapshot is 1 object, containing all our messages at once.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>I want to display the latest messages at the top, so I&#8217;m looping over my getChats, and push the data we need into a helperArray called &#8216;ascChats&#8217;. The create a new variable and set it to the reverse version of the regular ascChats array. This way the latest messages are stored at the top. <strong>Don&#8217;t forget to push the end result to our state!<\/strong> So we can use it in our component.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>For the reversing of the array to display the latest messages at the top&#8230; I&#8217;m pretty sure firebase will have a built-in function for this. But hey&#8230; Now we&#8217;ve done some javascript array cardio today as well \ud83d\ude42<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-finalize-our-chatbox\">Finalize our Chatbox<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Now that we have our messages in the state of our Chatbox, we can list them in our chatbox! Yaay.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Update the render method in Chatbox.js like this:<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre class=\"wp-block-code\"><code>\/\/ Chatbox.js\n...\nrender(){\n  return(\n    &lt;div className=\"chatbox\"&gt;\n      &lt;ul className='chat-list'&gt;\n        {this.state.chats.map(chat =&gt; {\n          const postDate = new Date(chat.date);\n          return(\n            &lt;li key={chat.id}&gt;\n              &lt;em&gt;{postDate.getDate() + '\/' + (postDate.getMonth()+1)}&lt;\/em&gt;\t\t\t\t\t\t\t\t \n              &lt;strong&gt;{chat.user}:&lt;\/strong&gt; \t\t\t\t\t\t\t\t \n              {chat.message}\n            &lt;\/li&gt;\n          );\n        })}\n      &lt;\/ul&gt;\n    &lt;\/div&gt;\n  );\n}\n...<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>We loop over the chat messages in our state and display them in our &#8220;chat-list&#8221;. Pooof! Our chat app is alive, just like that!!<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>This should do the trick?! A fully functioning React Chat App linked to the Realtime Database in Firebase! Let me know if you got stuck somewhere or if something is not explained correctly. I&#8217;ll adjust my tutorial.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>As I said before, I switched to using Vuejs instead of React. I&#8217;ll ad a link to a Vue-firebase setup as well in the related articles. Or, if you landed on this page and missed part 1 of the React Firebase setup, that one can be found as a related article as well.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Hope you enjoyed it and that my tutorial gave you some more insights!<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p>Peace.<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Building a simple chat application with React, React Router, and Firebase. We are using the Firebase  Realtime database for instant chat functionality.<\/p>\n","protected":false},"author":1,"featured_media":902,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[211],"tags":[55,56,57,58,59],"class_list":["post-1179","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development-nl","tag-chat","tag-chatbox","tag-firebase","tag-react","tag-realtime"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>React Chat-app met Firebase &amp; Authenticatie (deel 2) | Weichie.com<\/title>\n<meta name=\"description\" content=\"Eenvoudie chat app bouwen met React, React Router en Firebase. We gebruiken de Firebase Realtime-database voor directe chat functionaliteit.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create a React Chat-app with Firebase, React Router &amp; Authentication (part 2) | Weichie\" \/>\n<meta property=\"og:description\" content=\"Building a simple chat application with React, React Router, and Firebase. We are using the Firebase Realtime database for instant chat functionality.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Weichie.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/weichiecom\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-18T07:13:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-05T15:42:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/website-maken-bij-weichie.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"weichie\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Create a React Chat-app with Firebase, React Router &amp; Authentication (part 2) | Weichie\" \/>\n<meta name=\"twitter:description\" content=\"Building a simple chat application with React, React Router, and Firebase. We are using the Firebase Realtime database for instant chat functionality.\" \/>\n<meta name=\"twitter:label1\" content=\"Geschreven door\" \/>\n\t<meta name=\"twitter:data1\" content=\"weichie\" \/>\n\t<meta name=\"twitter:label2\" content=\"Geschatte leestijd\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/\"},\"author\":{\"name\":\"weichie\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#\\\/schema\\\/person\\\/36b4fff07382bc08a5c566728d9c579f\"},\"headline\":\"Een React Chat-app maken met Firebase, React Router &#038; Authenticatie (deel 2)\",\"datePublished\":\"2020-06-18T07:13:38+00:00\",\"dateModified\":\"2024-02-05T15:42:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/\"},\"wordCount\":1564,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/web-design-agency-brussels-03.jpg\",\"keywords\":[\"Chat\",\"Chatbox\",\"firebase\",\"react\",\"realtime\"],\"articleSection\":[\"Development\"],\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/\",\"url\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/\",\"name\":\"React Chat-app met Firebase & Authenticatie (deel 2) | Weichie.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/web-design-agency-brussels-03.jpg\",\"datePublished\":\"2020-06-18T07:13:38+00:00\",\"dateModified\":\"2024-02-05T15:42:49+00:00\",\"description\":\"Eenvoudie chat app bouwen met React, React Router en Firebase. We gebruiken de Firebase Realtime-database voor directe chat functionaliteit.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/web-design-agency-brussels-03.jpg\",\"contentUrl\":\"https:\\\/\\\/weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/web-design-agency-brussels-03.jpg\",\"width\":1080,\"height\":1080,\"caption\":\"React chat app with firebase mockup\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/blog\\\/react-firebase-chat-app-part-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/weichie.com\\\/nl\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Een React Chat-app maken met Firebase, React Router &#038; Authenticatie (deel 2)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#website\",\"url\":\"https:\\\/\\\/weichie.com\\\/nl\\\/\",\"name\":\"Weichie.com\",\"description\":\"Digital Agency in Brussels &amp; New York\",\"publisher\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#organization\"},\"alternateName\":\"Weichie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/weichie.com\\\/nl\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl-NL\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#organization\",\"name\":\"Weichie.com\",\"alternateName\":\"Weichie\",\"url\":\"https:\\\/\\\/weichie.com\\\/nl\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Weichie_full.png\",\"contentUrl\":\"https:\\\/\\\/weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Weichie_full.png\",\"width\":1181,\"height\":177,\"caption\":\"Weichie.com\"},\"image\":{\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/weichiecom\\\/\",\"https:\\\/\\\/www.instagram.com\\\/weichiecom\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/weichie\\\/\"],\"description\":\"A digital agency based in Brussels and New York. We create high-quality digital experiences for brands and help them promote their business through the online world! Specialised in websites, e-commerce, SEO and applications.\",\"email\":\"hello@weichie.com\",\"telephone\":\"+32 469 129 449\",\"legalName\":\"Weichie.com\",\"vatID\":\"0782.257.983\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1\",\"maxValue\":\"10\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/weichie.com\\\/nl\\\/#\\\/schema\\\/person\\\/36b4fff07382bc08a5c566728d9c579f\",\"name\":\"weichie\",\"sameAs\":[\"https:\\\/\\\/weichie.com\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"React Chat-app met Firebase & Authenticatie (deel 2) | Weichie.com","description":"Eenvoudie chat app bouwen met React, React Router en Firebase. We gebruiken de Firebase Realtime-database voor directe chat functionaliteit.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/","og_locale":"nl_NL","og_type":"article","og_title":"Create a React Chat-app with Firebase, React Router & Authentication (part 2) | Weichie","og_description":"Building a simple chat application with React, React Router, and Firebase. We are using the Firebase Realtime database for instant chat functionality.","og_url":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/","og_site_name":"Weichie.com","article_publisher":"https:\/\/www.facebook.com\/weichiecom\/","article_published_time":"2020-06-18T07:13:38+00:00","article_modified_time":"2024-02-05T15:42:49+00:00","og_image":[{"width":1024,"height":400,"url":"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/website-maken-bij-weichie.jpg","type":"image\/jpeg"}],"author":"weichie","twitter_card":"summary_large_image","twitter_title":"Create a React Chat-app with Firebase, React Router & Authentication (part 2) | Weichie","twitter_description":"Building a simple chat application with React, React Router, and Firebase. We are using the Firebase Realtime database for instant chat functionality.","twitter_misc":{"Geschreven door":"weichie","Geschatte leestijd":"8 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#article","isPartOf":{"@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/"},"author":{"name":"weichie","@id":"https:\/\/weichie.com\/nl\/#\/schema\/person\/36b4fff07382bc08a5c566728d9c579f"},"headline":"Een React Chat-app maken met Firebase, React Router &#038; Authenticatie (deel 2)","datePublished":"2020-06-18T07:13:38+00:00","dateModified":"2024-02-05T15:42:49+00:00","mainEntityOfPage":{"@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/"},"wordCount":1564,"commentCount":0,"publisher":{"@id":"https:\/\/weichie.com\/nl\/#organization"},"image":{"@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/web-design-agency-brussels-03.jpg","keywords":["Chat","Chatbox","firebase","react","realtime"],"articleSection":["Development"],"inLanguage":"nl-NL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/","url":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/","name":"React Chat-app met Firebase & Authenticatie (deel 2) | Weichie.com","isPartOf":{"@id":"https:\/\/weichie.com\/nl\/#website"},"primaryImageOfPage":{"@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#primaryimage"},"image":{"@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/web-design-agency-brussels-03.jpg","datePublished":"2020-06-18T07:13:38+00:00","dateModified":"2024-02-05T15:42:49+00:00","description":"Eenvoudie chat app bouwen met React, React Router en Firebase. We gebruiken de Firebase Realtime-database voor directe chat functionaliteit.","breadcrumb":{"@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/"]}]},{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#primaryimage","url":"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/web-design-agency-brussels-03.jpg","contentUrl":"https:\/\/weichie.com\/wp-content\/uploads\/2023\/02\/web-design-agency-brussels-03.jpg","width":1080,"height":1080,"caption":"React chat app with firebase mockup"},{"@type":"BreadcrumbList","@id":"https:\/\/weichie.com\/nl\/blog\/react-firebase-chat-app-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/weichie.com\/nl\/"},{"@type":"ListItem","position":2,"name":"Een React Chat-app maken met Firebase, React Router &#038; Authenticatie (deel 2)"}]},{"@type":"WebSite","@id":"https:\/\/weichie.com\/nl\/#website","url":"https:\/\/weichie.com\/nl\/","name":"Weichie.com","description":"Digital Agency in Brussels &amp; New York","publisher":{"@id":"https:\/\/weichie.com\/nl\/#organization"},"alternateName":"Weichie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/weichie.com\/nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl-NL"},{"@type":"Organization","@id":"https:\/\/weichie.com\/nl\/#organization","name":"Weichie.com","alternateName":"Weichie","url":"https:\/\/weichie.com\/nl\/","logo":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/weichie.com\/nl\/#\/schema\/logo\/image\/","url":"https:\/\/weichie.com\/wp-content\/uploads\/2023\/11\/Weichie_full.png","contentUrl":"https:\/\/weichie.com\/wp-content\/uploads\/2023\/11\/Weichie_full.png","width":1181,"height":177,"caption":"Weichie.com"},"image":{"@id":"https:\/\/weichie.com\/nl\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/weichiecom\/","https:\/\/www.instagram.com\/weichiecom\/","https:\/\/www.linkedin.com\/company\/weichie\/"],"description":"A digital agency based in Brussels and New York. We create high-quality digital experiences for brands and help them promote their business through the online world! Specialised in websites, e-commerce, SEO and applications.","email":"hello@weichie.com","telephone":"+32 469 129 449","legalName":"Weichie.com","vatID":"0782.257.983","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1","maxValue":"10"}},{"@type":"Person","@id":"https:\/\/weichie.com\/nl\/#\/schema\/person\/36b4fff07382bc08a5c566728d9c579f","name":"weichie","sameAs":["https:\/\/weichie.com"]}]}},"_links":{"self":[{"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/posts\/1179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/comments?post=1179"}],"version-history":[{"count":0,"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/posts\/1179\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/media\/902"}],"wp:attachment":[{"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/media?parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/categories?post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weichie.com\/nl\/wp-json\/wp\/v2\/tags?post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}