Fireship · @fireship
I built a chat app in 7 minutes with React & Firebase
Uploaded September 23, 2020 · Length 8:53
Summary
Build a basic chat app in 7 minutes with React & Firebase, including user authentication and real-time data updates.
- react
- firebase
- chat app
- real-time data
- user authentication
- javascript
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
Once upon a time, building a real-time chat app required a lot of carefully engineered code.
- 0:05
Today, when you combine tools like React and Firebase, you can build a basic chat app from
- 0:09
scratch in under 7 minutes. The app you'll build today is live on the internet, so feel free to
- 0:13
check it out. Now, I already know what most of you are thinking. You'll go into the live demo,
- 0:16
say some terrible things, and try to break the app by spamming it with a ton of messages.
- 0:20
But we can get a lot done in 7 minutes. There's plenty of time to implement security logic,
- 0:24
and we'll even write some backend code to ban a user for life if they violate our community
- 0:28
guidelines, but most importantly you'll learn how to authenticate users with Firebase and
- 0:32
how to work with real-time data in Firestore using React hooks.
- 0:36
If you're new here, like and subscribe, and you can reference the code on GitHub.
- 0:39
And if you want to go beyond the basics, check out this React Fire article by Jarrett Helton
- 0:43
on FireShip.io.
- 0:44
Before we get started, let's quickly take a look at what we're building today.
- 0:47
It's a single group chat room that everybody can participate in, kind of like Super Chat
- 0:51
on YouTube.
- 0:52
To enter the chat, a user must log in with their Google account.
- 0:54
Once logged in, they can post messages into the chat.
- 0:57
Each message is a document in the Firestore database.
- 1:00
It contains the text, user ID, and timestamp for that message.
- 1:03
We make a query to the database for the most recent messages.
- 1:06
Whenever the underlying data changes on the backend, the React app will update with the
- 1:10
most recent messages on the frontend.
- 1:12
It's very easy to implement, and by the end of this video, you'll have a great starting
- 1:15
point for building really any type of real-time application.
- 1:18
Let's go ahead and get started.
- 1:19
Open up the terminal, and then I'll set a timer for 7 minutes.
- 1:23
Run npx create react app to create an initial React project.
- 1:26
code followed by the name of your app to open it in VS Code. We have two extra dependencies to
- 1:30
install, Firebase and React Firebase hooks. Once installed, we can open up the app.js file,
- 1:36
which is where we'll write all of our front-end code. Go ahead and delete the boilerplate code
- 1:39
except for the app in the header. First, we'll import the Firebase SDK along with Firestore for
- 1:44
our database and Auth for user authentication. Then we'll import a couple of hooks here to make
- 1:49
it easier to work with Firebase in React. We'll call Firebase initialize app to identify our
- 1:53
project, and then we'll make a reference to the Auth and Firestore SDKs as global variables.
- 1:58
But we don't have a Firebase project yet, so let's create one by clicking Add Project from


