React
Templates

Slack Clone App

9min

React Slack Clone App

Introduction

In this guide, we will keep exploring the Parse React hook in useful situations by creating a Slack Clone App. The App will have basic features such as signup/login, channels, and real-time chat. In addition, the React components highlight the usefulness of real-time notifications using Live Query, User management capabilities, and the flexibility to perform queries (relational).

At any moment you can quickly deploy a slack clone app on Vercel:

Prerequisites

To complete this tutorial, you will need:

Goal

To build a Slack clone application on React using the @parse/react hook.

1 - Creating your Parse app from a template

This application comprises two database classes: Channel and Message, containing pointers to the Parse User class. Instead of creating the app and database classes from scratch, let’s clone an existing template at Back4App Database Hub. Click on the “Clone Database” button and proceed with logging in and creating your app. For more details on how to clone please check the clone App guide.

Document image


Now your App has the complete backend structure necessary to create your Slack Clone on Back4App.

2 - Enabling Live Query

Now that you have created the App and classes, you need to enable the live query(real-time). Go to your Back4App dashboard and navigate to App Settings > Server Settings > Server URL and Live Query. After activating your Back4App subdomain, you can then activate Live Query by selecting the classes Message and Channel. After that, save the changes.

Document image


The URL above is your Live Query URL make sure to copy it in order to properly initialize the Parse hook.

Let’s now dive into the core React components: ChannelList, MessageList, and Home.

3 - The List components

The ChannelList and MessageList components use the @parse/react hook to retrieve the User data through Live Query. They have the same pattern structure as in the React LiveChat guide. They are instantiated with initial parameters (retrieved via the props object) that dynamically compose their Live Query query. Take a look at their queries and how the classes are related to each other:

JavaScript
TypeScript


These queries will be running every time there is a change in the classes data, so if another user in the channel sends a message, you will see it appearing there in real-time.

4 - The Home component

The Home component acts as the main application screen, in which the list components are conditionally rendered and instantiated when needed. You can find below the component code. Take a look at the functions for creating channels and inviting users to them.

Home.js
Home.tsx


This approach of dynamically instantiating the Live Query components allows us to reuse them whenever the user changes the active channel, creates a new one, sends a message, etc. Here is how the complete App will look.

Document image


5 - Deploy on Vercel

At any time you can deploy the application on vercel by clicking on the link below:

Make sure you have your Application ID, Client Key and LiveQuery URL. For the keys you can go to App Settings -> Security & Keys and then copy. For the Live Query URL you can go to Step 2 and copy it.

Conclusion

At the end of this guide, you learned more about using the Parse React hook for live queries in Parse and how to use Back4App’s Database Hub.