<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: angela300</title>
    <description>The latest articles on DEV Community by angela300 (@angela300).</description>
    <link>https://dev.to/angela300</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1236288%2F9288c2fd-bed9-438b-865b-df1871a575ac.png</url>
      <title>DEV Community: angela300</title>
      <link>https://dev.to/angela300</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/angela300"/>
    <language>en</language>
    <item>
      <title>A SIMPLE SMART CONTRACT</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Mon, 01 Apr 2024 07:05:48 +0000</pubDate>
      <link>https://dev.to/angela300/a-simple-smart-contract-9ak</link>
      <guid>https://dev.to/angela300/a-simple-smart-contract-9ak</guid>
      <description>&lt;p&gt;This contract is a basic example of a cryptocurrency token contract, and it is written in Solidity, the programming language commonly used for Ethereum smart contracts.&lt;/p&gt;

&lt;p&gt;This contract is a simple implementation of the ERC20 token standard, which is a widely adopted standard for fungible tokens on the Ethereum blockchain. It allows for basic token transfers, approvals, and allowance mechanisms.&lt;/p&gt;

&lt;p&gt;Deploying smart contracts involves interacting with the Ethereum blockchain and requires a solid understanding of blockchain technology and smart contract development. Always ensure proper testing and auditing before deploying any smart contract to the mainnet or any public blockchain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Simple ERC20 Token Contract
contract SimpleToken {
    string public name;
    string public symbol;
    uint8 public decimals;
    uint256 public totalSupply;
    mapping(address =&amp;gt; uint256) public balanceOf;
    mapping(address =&amp;gt; mapping(address =&amp;gt; uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals,
        uint256 _initialSupply
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        totalSupply = _initialSupply * 10**uint256(_decimals);
        balanceOf[msg.sender] = totalSupply;
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(_to != address(0), "Invalid recipient address");
        require(balanceOf[msg.sender] &amp;gt;= _value, "Insufficient balance");

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_to != address(0), "Invalid recipient address");
        require(balanceOf[_from] &amp;gt;= _value, "Insufficient balance");
        require(allowance[_from][msg.sender] &amp;gt;= _value, "Allowance exceeded");

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Login with Google on React Native Expo</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Mon, 18 Mar 2024 02:52:38 +0000</pubDate>
      <link>https://dev.to/angela300/login-with-google-on-react-native-expo-3h9n</link>
      <guid>https://dev.to/angela300/login-with-google-on-react-native-expo-3h9n</guid>
      <description>&lt;p&gt;This will work for web, IOS and Adnroid&lt;br&gt;
Create a new expo project:&lt;br&gt;
&lt;code&gt;npx create-expo-app tutorial-google&lt;/code&gt;&lt;br&gt;
Install dependencies that we will need&lt;br&gt;
Expo auth session will manage the sign in with Google&lt;br&gt;
Expo-crypto and expo-web-browser are core dependencies of expo-auth-session&lt;br&gt;
We will also need react-native-web, react-dom and @expo/webpack-config&lt;br&gt;
We will also need react native async storage&lt;br&gt;
&lt;code&gt;npx expo install expo-auth-session expo-crypto expo-web-browser react-native-web react-dom @expo/webpack-config @react-native-async-storage/async-storage&lt;/code&gt;&lt;br&gt;
Create a project in Google cloud:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gjrnxwpgm3hivr8lnq4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gjrnxwpgm3hivr8lnq4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo6xfpxkcbzr134ogw96n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo6xfpxkcbzr134ogw96n.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Select the project&lt;br&gt;
We are going to create an OAuth client ID&lt;br&gt;
Go to API’s and services and click on OAuth consent screen&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsu6em1kmmf2i3hqsbki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsu6em1kmmf2i3hqsbki.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
On enable APIs &amp;amp; services, click on Create credentials:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0m8c4dsyxpzt9uvfk7li.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0m8c4dsyxpzt9uvfk7li.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
After clicking on Create credentials, on the dropdown screen that comes up, click on OAuth Client ID&lt;br&gt;
Next click on configure consent screen&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ficu7x81squu6zr0j8mqv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ficu7x81squu6zr0j8mqv.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Click on External - availabe to any User with a Google test account and click on create.&lt;br&gt;
This is the consent screen&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1hog5n5e9wnvkiwfw7jz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1hog5n5e9wnvkiwfw7jz.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Under app name, fill in ‘google-tutorial’ or your preferred name&lt;br&gt;
Under user support email, provide one&lt;br&gt;
You can specify a logo, app domain, which are all optional&lt;br&gt;
Under developer contact information, add another email&lt;br&gt;
Hit on save and continue&lt;br&gt;
Under scopes, you can add users if you want.&lt;br&gt;
Click on save and continue&lt;br&gt;
Now we have a consent screen.&lt;br&gt;
Lets get a client id for the web:&lt;br&gt;
Click on credentials, and under application type, click on Web application:&lt;br&gt;
Under authorized Javascript Origins, we need to add some URL’s, which are the URL’s for the application&lt;br&gt;
To get the URL, run the project on the web:&lt;br&gt;
&lt;code&gt;npx expo start –web –https&lt;/code&gt;&lt;br&gt;
The app will open in the web, copy that URL and add it:&lt;br&gt;
&lt;a href="https://localhost:19006" rel="noopener noreferrer"&gt;https://localhost:19006&lt;/a&gt;&lt;br&gt;
This is the same link under Authorized Redirect URI’s&lt;br&gt;
Click on ‘Create’&lt;br&gt;
On the screen that pops up, Copy the Client ID&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpmbscaquwk2jlq10yio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpmbscaquwk2jlq10yio.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flekr0zuv5lr3ldmvf5nj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flekr0zuv5lr3ldmvf5nj.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
On the App.js file in your Expo  app, paste the client ID on there for later use.&lt;br&gt;
Lets also get the ID’s for  IOS:&lt;br&gt;
Click on create credentials, Click on OAuth Client ID, the select IOS under Application type&lt;br&gt;
For IOS, we will need the bundle ID.&lt;br&gt;
On your app’s root folder:&lt;br&gt;
Run the command, &lt;code&gt;npx expo prebuild&lt;/code&gt;&lt;br&gt;
Under the package name add: com.betomoedamo.tutorialgoogle&lt;br&gt;
We also have the IOS Identifier which is going to be the same as package name above&lt;br&gt;
Hit Enter&lt;br&gt;
Once this is completed, we can see that the bundle identifier has been added under IOS:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmn74bd58j3c89pkzz3bi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmn74bd58j3c89pkzz3bi.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Copy that bundle Identifier and paste it in the Bundle ID field under Create OAuth Client ID:&lt;br&gt;
Hit create, and on the popup screen that comes up, copy the client ID.&lt;br&gt;
Paste for later use in your App.js file, just as you did with the client ID for the web&lt;br&gt;
Create a credential for Android&lt;br&gt;
Click on create credentials, Click on OAuth Client ID, the select Android under Application type&lt;br&gt;
Under package name, paste the name attached to “package” under android in app.js. It will the same as the Bundle ID for IOS&lt;br&gt;
We will also need a SHA-1 certificate fingerprint&lt;br&gt;
To obtain this for android,&lt;br&gt;
run this command in your app’s  root folder: &lt;code&gt;expo credentials:manager&lt;/code&gt;&lt;br&gt;
Under platform, select Android&lt;br&gt;
Under ‘You are currently in a directory with @betomoedano/tutorial-google experience. Do you want to select it?...’, Select Yes&lt;br&gt;
Under ‘What do you want to do?’ Select Update upload Keystore&lt;br&gt;
Then select Generate new keystore&lt;br&gt;
Select on Go back to the experience overview, and here, we have the SHA-1 fingerprint&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68suef3f1l2j8smxu6r3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68suef3f1l2j8smxu6r3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the SHA-1 certificate fingerprint and paste it under the required field in creating credentials.&lt;br&gt;
Hit create and on the pop up screen that comes up, copy the client ID an paste it your App.js file for later use&lt;br&gt;
That was the most difficult part, now we can start creating the code for the application&lt;br&gt;
In app.js, import WebBrowser:&lt;br&gt;
&lt;code&gt;Import * as WebBrowser from “expo-web-browser”&lt;/code&gt;&lt;br&gt;
Initialize the WebBrowser with this command:&lt;br&gt;
&lt;code&gt;WebBrowser.maybeCompleteAuthSession();&lt;/code&gt;&lt;br&gt;
Also add this import in your app.js:&lt;br&gt;
&lt;code&gt;Import * as Google from “expo-auth-session/providers/google”&lt;/code&gt;&lt;br&gt;
To save the information of the user when they sign in so that they do not have to sign in again, we will use async storage:&lt;br&gt;
&lt;code&gt;Import AsyncStorage from “@react-native-async-storage/async-storage”&lt;/code&gt;&lt;br&gt;
Also add this to the imports section:&lt;br&gt;
&lt;code&gt;Import * as React from “react”&lt;/code&gt;&lt;br&gt;
Add a variable userInfo and initialize it to null:&lt;br&gt;
&lt;code&gt;Const [userInfo, setUserInfo] = React.useState(null);&lt;/code&gt;&lt;br&gt;
Next, lets create a hook that is going to enable us to signin in all of our applications:&lt;br&gt;
Here will now add the client ID’s we had saved for later use.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Const [request, response, promptAsync] = Google.useAuthRequest({
})


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Populate the above array to appear as this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdvzzxtvxg7xu679ek01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdvzzxtvxg7xu679ek01.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
We will need to prompt the user to signin with Google, by adding this button in the app:&lt;br&gt;
&lt;br&gt;
Let’s now run the app on the web and see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffyn7w3783y6g99osb1j5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffyn7w3783y6g99osb1j5.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
This is working, though it’s not handling the response,&lt;br&gt;
Let’s go back to the application and handle the response&lt;br&gt;
We will need to create a get userinfo function and a handlesigninwithgoogle function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fem27zbig1avkpibynt76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fem27zbig1avkpibynt76.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The getuserinfo function is called inside the signinwithgoogle function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2bkdgriszajw3qy8fanb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2bkdgriszajw3qy8fanb.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
To run the signinwithgoogle function, we will now need to create a useEffect hook:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpoz8fnzpaq06qbiu1q8o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpoz8fnzpaq06qbiu1q8o.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
To enable sign out, lets add a button to delete local storage:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhy1xec8v9ceiqw8vpv0a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhy1xec8v9ceiqw8vpv0a.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
We added the json.Stringify(userInfo) above to test if the sign in and delete local storage are working. You can test them out and see.&lt;br&gt;
Test on the web&lt;br&gt;
On a successful sign in with google, we have all the information about the user:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft11dswasua49vu6doqlt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft11dswasua49vu6doqlt.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Also test if its working on IOS and android:&lt;br&gt;
To test it in android and IOS, we need to provide a scheme, which will help us redirect the user back to the application&lt;br&gt;
Add the scheme into your app.json as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98g5mhxewhla0buzgsir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98g5mhxewhla0buzgsir.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
You can name the scheme as you want. In my case, I named it ‘myGoogleApp’&lt;br&gt;
A)  Test on IOS&lt;br&gt;
Next we need to build the app:&lt;br&gt;
To build for IOS, run the command, npx expo run:ios&lt;br&gt;
With no user signed it yet, the userInfo will be null:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgrmlwgehzph661yuywxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgrmlwgehzph661yuywxy.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
On proceeding to signin with google, you might encounter this error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbcaawbhnl7605nfxsfw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbcaawbhnl7605nfxsfw.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
To remove the error, edit your sign in with google button to appear as this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbiw4te0ai4b3he5jatbl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbiw4te0ai4b3he5jatbl.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To also ensure the userinfo appears in a nice format, edit the text stringify to appear as this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjio3jotmcskrj7jo47zv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjio3jotmcskrj7jo47zv.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz78fphce7e44lvy9wsrp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz78fphce7e44lvy9wsrp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;b) Test on android:&lt;br&gt;
Now also text if its working on android.&lt;br&gt;
We need to create the actual build for android: npx expo run:android&lt;br&gt;
Before sign in, it will appear like this in android:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhunrvnpkqr2z73yc0igt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhunrvnpkqr2z73yc0igt.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Upon a successful sign in, it will appear as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mkys4oqdanptogx42h4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mkys4oqdanptogx42h4.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Thanks for reading through!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting Started with Blockchain Programming: A Beginner's Guide</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Mon, 18 Mar 2024 02:28:49 +0000</pubDate>
      <link>https://dev.to/angela300/title-getting-started-with-blockchain-programming-a-beginners-guide-p69</link>
      <guid>https://dev.to/angela300/title-getting-started-with-blockchain-programming-a-beginners-guide-p69</guid>
      <description>&lt;p&gt;Blockchain programming involves developing applications that leverage the decentralized and immutable nature of blockchain technology. In this guide, we'll explore the fundamental concepts of blockchain programming, discuss the popular blockchain platforms, and provide a step-by-step approach to start building blockchain applications.&lt;/p&gt;

&lt;p&gt;Understanding Blockchain Technology:&lt;/p&gt;

&lt;p&gt;What is blockchain?&lt;br&gt;
Core principles: decentralization, transparency, immutability, and security.&lt;br&gt;
Components of a blockchain: blocks, transactions, consensus mechanisms.&lt;br&gt;
Exploring Blockchain Platforms:&lt;/p&gt;

&lt;p&gt;Ethereum: A leading blockchain platform for decentralized applications (DApps) and smart contracts.&lt;br&gt;
Hyperledger Fabric: An enterprise-grade permissioned blockchain framework.&lt;br&gt;
Binance Smart Chain (BSC): A blockchain platform compatible with Ethereum Virtual Machine (EVM) for deploying smart contracts.&lt;br&gt;
Solana: A high-performance blockchain platform designed for scalability and low transaction fees.&lt;br&gt;
Polkadot: A multi-chain blockchain platform interoperable with other blockchains.&lt;br&gt;
Learning Blockchain Programming Languages:&lt;/p&gt;

&lt;p&gt;Solidity: A high-level language for writing smart contracts on Ethereum.&lt;br&gt;
JavaScript: Used for frontend development and interacting with blockchain networks via web3.js or ethers.js.&lt;br&gt;
GoLang: Preferred for building blockchain infrastructure and core blockchain protocols.&lt;br&gt;
Rust: Used in projects like Polkadot for building blockchain runtime environments.&lt;br&gt;
Setting Up Your Development Environment:&lt;/p&gt;

&lt;p&gt;Installing necessary software: Node.js, npm, Git, IDE (e.g., Visual Studio Code).&lt;br&gt;
Choosing a blockchain platform and setting up a development environment.&lt;br&gt;
Installing development tools and libraries specific to your chosen platform.&lt;br&gt;
Writing Your First Smart Contract:&lt;/p&gt;

&lt;p&gt;Understanding the structure of a smart contract.&lt;br&gt;
Writing a simple smart contract using Solidity.&lt;br&gt;
Compiling and deploying the smart contract to a local blockchain network.&lt;br&gt;
Interacting with Blockchain Networks:&lt;/p&gt;

&lt;p&gt;Using web3.js or ethers.js to interact with Ethereum and Ethereum-compatible blockchains.&lt;br&gt;
Sending transactions, querying data, and listening to events.&lt;br&gt;
Developing frontend interfaces for blockchain applications.&lt;br&gt;
Testing and Debugging:&lt;/p&gt;

&lt;p&gt;Writing unit tests for smart contracts using testing frameworks like Truffle or Hardhat.&lt;br&gt;
Using debugging tools and techniques to identify and fix issues in smart contracts.&lt;br&gt;
Deploying Blockchain Applications:&lt;/p&gt;

&lt;p&gt;Deploying smart contracts to testnets and mainnet.&lt;br&gt;
Considerations for gas fees, transaction confirmation times, and network congestion.&lt;br&gt;
Upgrading and managing deployed contracts.&lt;br&gt;
Security Best Practices:&lt;/p&gt;

&lt;p&gt;Understanding common security vulnerabilities in smart contracts (e.g., reentrancy, integer overflow).&lt;br&gt;
Implementing security measures such as access control, input validation, and code audits.&lt;br&gt;
Following best practices for secure smart contract development.&lt;br&gt;
Resources and Further Learning:&lt;/p&gt;

&lt;p&gt;Official documentation and developer guides for blockchain platforms.&lt;br&gt;
Online courses and tutorials on blockchain programming.&lt;br&gt;
Community forums, developer communities, and hackathons.&lt;br&gt;
Books and research papers on blockchain technology and programming.&lt;/p&gt;

&lt;p&gt;Blockchain programming offers a unique opportunity to build decentralized, transparent, and secure applications that can revolutionize various industries. &lt;/p&gt;

&lt;p&gt;Let's take a look at one of blockchain's core programming languages, Solidity&lt;/p&gt;

&lt;p&gt;Solidity is a high-level programming language specifically designed for writing smart contracts on blockchain platforms like Ethereum. Smart contracts are self-executing contracts with the terms of the agreement between the buyer and the seller directly written into code. They automatically enforce and execute these terms when predefined conditions are met. This guide will provide a step-by-step introduction to Solidity, covering the basics of smart contract development for Ethereum.&lt;/p&gt;

&lt;p&gt;Understanding Smart Contracts:&lt;/p&gt;

&lt;p&gt;What are smart contracts?&lt;br&gt;
Advantages of smart contracts.&lt;br&gt;
Applications of smart contracts in various industries.&lt;br&gt;
Setting Up Your Development Environment:&lt;/p&gt;

&lt;p&gt;Installing Node.js and npm.&lt;br&gt;
Installing Solidity compiler (solc).&lt;br&gt;
Choosing an Ethereum development framework (e.g., Truffle, Hardhat).&lt;br&gt;
Setting up a local blockchain network for testing (e.g., Ganache).&lt;br&gt;
Basics of Solidity:&lt;/p&gt;

&lt;p&gt;Syntax and structure of Solidity code.&lt;br&gt;
Data types: uint, int, address, string, bool, etc.&lt;br&gt;
Variables and constants.&lt;br&gt;
Functions: declaration, parameters, return values.&lt;br&gt;
Control structures: if-else statements, loops.&lt;br&gt;
Writing Your First Smart Contract:&lt;/p&gt;

&lt;p&gt;Creating a simple "Hello World" smart contract.&lt;br&gt;
Deploying the contract to a local blockchain network.&lt;br&gt;
Interacting with the contract using Remix IDE or Truffle console.&lt;br&gt;
Understanding Ethereum Development Tools:&lt;/p&gt;

&lt;p&gt;Remix IDE: An online integrated development environment for Solidity.&lt;br&gt;
Truffle: A popular development framework for Ethereum that provides tools for compiling, testing, and deploying smart contracts.&lt;br&gt;
Hardhat: Another powerful development environment for Ethereum with built-in tasks for testing and deployment.&lt;br&gt;
Advanced Solidity Concepts:&lt;/p&gt;

&lt;p&gt;Inheritance: Reusing code with inheritance.&lt;br&gt;
Modifiers: Adding conditions to functions.&lt;br&gt;
Events: Emitting events to notify external applications.&lt;br&gt;
Error handling: Handling exceptions and errors.&lt;br&gt;
Testing Your Smart Contracts:&lt;/p&gt;

&lt;p&gt;Writing unit tests using frameworks like Mocha and Chai.&lt;br&gt;
Testing contract behavior under different scenarios.&lt;br&gt;
Debugging tools and techniques.&lt;br&gt;
Deploying Smart Contracts:&lt;/p&gt;

&lt;p&gt;Deploying contracts to the Ethereum mainnet or testnets.&lt;br&gt;
Choosing the right gas price and gas limit.&lt;br&gt;
Interacting with deployed contracts using web3.js or ethers.js.&lt;br&gt;
Best Practices and Security Considerations:&lt;/p&gt;

&lt;p&gt;Design patterns for smart contract development (e.g., Factory, Proxy, State).&lt;br&gt;
Security vulnerabilities and common pitfalls.&lt;br&gt;
Code review and auditing.&lt;br&gt;
Resources and Further Learning:&lt;/p&gt;

&lt;p&gt;Official Solidity documentation.&lt;br&gt;
Online tutorials and courses.&lt;br&gt;
Community forums and developer communities.&lt;br&gt;
Books and research papers on blockchain and smart contract development.&lt;br&gt;
Conclusion:&lt;br&gt;
Solidity opens up a world of possibilities for building decentralized applications (DApps) and executing trustless transactions on the Ethereum blockchain. By mastering the basics of Solidity and understanding smart contract development principles, you can contribute to the growing ecosystem of decentralized finance (DeFi), non-fungible tokens (NFTs), and other blockchain-based innovations. Start your journey into the exciting world of blockchain development with Solidity today!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Simplifying Data Fetching from Sanity CMS in a ReactJS Application</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Wed, 13 Mar 2024 05:24:18 +0000</pubDate>
      <link>https://dev.to/angela300/simplifying-data-fetching-from-sanity-cms-in-a-reactjs-application-2hc1</link>
      <guid>https://dev.to/angela300/simplifying-data-fetching-from-sanity-cms-in-a-reactjs-application-2hc1</guid>
      <description>&lt;p&gt;Sanity is a powerful content management system (CMS) that empowers developers to efficiently manage and organize content for their applications. In this article, we'll explore how to seamlessly integrate Sanity with a ReactJS application, enabling developers to fetch existing data from Sanity and leverage it within their projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sanity CMS: Empowering Content Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sanity provides developers with a flexible and intuitive platform for content management. With its robust features and user-friendly interface, Sanity allows users to create, edit, and publish content across various channels effortlessly. By decoupling content from presentation, Sanity enables developers to maintain content consistency while adapting it to different layouts and formats, making it an ideal choice for modern web applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integrating Data Fetching from Sanity into a ReactJS Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To integrate Sanity with a ReactJS application, I followed the guide provided on the Sanity.io website titled "Create a Single Page Application with React and Sanity" (link: &lt;a href="https://www.sanity.io/guides/create-a-single-page-application-with-react-and-sanity"&gt;https://www.sanity.io/guides/create-a-single-page-application-with-react-and-sanity&lt;/a&gt;). This guide walks through the process of setting up a React application with Sanity and fetching existing data from the CMS.&lt;/p&gt;

&lt;p&gt;By following the steps outlined in the guide, I was able to establish a seamless connection between my ReactJS application and Sanity CMS. This enabled fetching data from Sanity and integrating it into my application's components, and allowed for dynamic content rendering and personalized user experiences.&lt;/p&gt;

&lt;p&gt;Integrating Sanity CMS with a ReactJS application offers a powerful solution for content management and data fetching. The flexibility and capabilities of Sanity enables the creation of robust and scalable applications that deliver rich and dynamic content to users. Whether you're building a simple website or a complex web application, integrating Sanity with ReactJS ensures that your project is well-equipped to meet the demands of modern web development.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>EmailJS: Simplifying Email Sending in a Web App</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Wed, 13 Mar 2024 04:59:09 +0000</pubDate>
      <link>https://dev.to/angela300/emailjs-simplifying-email-sending-in-a-web-app-40ce</link>
      <guid>https://dev.to/angela300/emailjs-simplifying-email-sending-in-a-web-app-40ce</guid>
      <description>&lt;p&gt;EmailJS is a powerful service that simplifies the process of sending emails directly from client-side JavaScript code. It offers a convenient solution for developers who want to incorporate email functionality into their web applications without the need to set up and maintain a backend server for handling email sending.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Importance of EmailJS:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplicity and Ease of Use:&lt;/strong&gt; EmailJS abstracts away the complexities of setting up email servers and APIs, providing a straightforward interface for sending emails. Developers can focus on building their applications without worrying about email infrastructure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client-Side Email Sending:&lt;/strong&gt; With EmailJS, emails can be sent directly from the client-side code of a web application. This is particularly useful for single-page applications (SPAs) and client-side frameworks like React, Angular, or Vue.js, where server-side processing may not be feasible or desired.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No Backend Required:&lt;/strong&gt; Since EmailJS handles the email sending process entirely on the client-side, there's no need to maintain a backend server solely for sending emails. This reduces development complexity and saves resources, especially for smaller projects or prototypes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost-Effective Solution:&lt;/strong&gt; EmailJS offers a free tier that allows developers to send a certain number of emails each month without incurring any costs. This makes it an attractive option for individuals and small businesses with limited budgets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customizable Templates:&lt;/strong&gt; EmailJS provides a template-based approach to email composition, allowing developers to create customizable email templates for various use cases. Templates can include dynamic content, making it easy to personalize emails based on user input or application data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration with Third-Party Services:&lt;/strong&gt; EmailJS integrates seamlessly with popular third-party services like Gmail, Outlook, and SendGrid, among others. This enables developers to leverage the features and reliability of these email providers while using EmailJS as the interface for sending emails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automation and Workflow:&lt;/strong&gt; EmailJS supports automation and workflow features, allowing developers to set up triggers and actions based on specific events in their application. This enables automated email notifications, reminders, and other communication workflows without manual intervention.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To use Email JS in a React App and send up to 200 free emails per month, follow this link, &lt;br&gt;
telerik.com/blogs/sending-emails-react-app-using-emailjs&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fetch data from Sanity content management system in an Expo app</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Mon, 11 Mar 2024 20:04:36 +0000</pubDate>
      <link>https://dev.to/angela300/fetche-data-from-sanity-content-management-system-in-an-expo-app-5aji</link>
      <guid>https://dev.to/angela300/fetche-data-from-sanity-content-management-system-in-an-expo-app-5aji</guid>
      <description>&lt;p&gt;Have you used the Sanity content management system before? &lt;br&gt;
Sanity is a powerful content management system (CMS) that allows developers to easily manage and organize content for their applications. In this article, we'll explore how to integrate Sanity with an Expo app, enabling you to fetch existing data from Sanity.&lt;/p&gt;

&lt;p&gt;Expo is an open-source framework and platform for building universal React applications, with a focus on mobile development. It allows developers to create high-quality iOS and Android apps using JavaScript and React Native&lt;/p&gt;

&lt;p&gt;Let's create a project that fetches data from Sanity in an Expo app. We'll start by setting up a new Sanity project, defining schemas, deploying it, and then creating an Expo app to fetch and display the data.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up Sanity:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Installing Sanity CLI:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open your terminal or command prompt.&lt;/p&gt;

&lt;p&gt;Run the following command to install the Sanity CLI globally:&lt;br&gt;
&lt;code&gt;npm install -g @sanity/cli&lt;/code&gt;&lt;br&gt;
Initialize a new Sanity project:&lt;br&gt;
Run the following command to initialize a new Sanity project:&lt;br&gt;
&lt;code&gt;sanity init&lt;/code&gt;&lt;br&gt;
Follow the prompts to create a new project. You can choose the default options for most settings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define schemas:&lt;/strong&gt;&lt;br&gt;
In your Sanity project directory, navigate to the schemas directory.&lt;br&gt;
Create a new file named post.js.&lt;br&gt;
Define the schema for a blog post inside post.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// schemas/post.js

export default {
    name: 'post',
    title: 'Post',
    type: 'document',
    fields: [
      {
        name: 'title',
        title: 'Title',
        type: 'string',
      },
      {
        name: 'body',
        title: 'Body',
        type: 'text',
      },
    ],
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploy the Sanity project:&lt;/strong&gt;&lt;br&gt;
Once you've defined your schemas, deploy your Sanity project to make the schemas and data accessible via an API:&lt;br&gt;
Follow the prompts to deploy your project.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sanity deploy&lt;/code&gt;&lt;br&gt;
The above command is to be run inside the sanity folder that resulted from initializing sanity above with &lt;code&gt;sanity init&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the Expo app
&lt;/h2&gt;

&lt;p&gt;Initialize a new Expo app&lt;/p&gt;

&lt;p&gt;In a separate directory, create a new Expo app:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;expo init sanityExpoApp&lt;/code&gt;&lt;br&gt;
Choose the blank template when prompted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install required packages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigate into the newly created Expo app directory:&lt;br&gt;
&lt;code&gt;cd sanityExpoApp&lt;/code&gt;&lt;br&gt;
Install the necessary packages for fetching data from Sanity:&lt;br&gt;
npm install @sanity/client&lt;br&gt;
Set up Sanity client:&lt;br&gt;
Create a new file named sanityClient.js in the root of your Expo project directory.&lt;br&gt;
Configure a Sanity client inside sanityClient.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// sanityClient.js

import sanityClient from '@sanity/client';

const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset-name',
  useCdn: true, // Enable the Content Delivery Network (CDN) for faster responses
});

export default client;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace 'your-project-id' and 'your-dataset-name' with your actual Sanity project ID and dataset name.&lt;/p&gt;

&lt;p&gt;Fetch data in the Expo app:&lt;br&gt;
Open the App.js file in your Expo project directory.&lt;br&gt;
Replace the existing code with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js

import React, { useState, useEffect } from 'react';
import { View, Text } from 'react-native';
import client from './sanityClient';

const App = () =&amp;gt; {
  const [posts, setPosts] = useState([]);

  useEffect(() =&amp;gt; {
    const fetchData = async () =&amp;gt; {
      try {
        const result = await client.fetch('*[_type == "post"]');
        setPosts(result);
      } catch (error) {
        console.error('Error fetching data:', error);
      }
    };

    fetchData();
  }, []);

  return (
    &amp;lt;View&amp;gt;
      &amp;lt;Text&amp;gt;Posts:&amp;lt;/Text&amp;gt;
      {posts.map((post, index) =&amp;gt; (
        &amp;lt;View key={index}&amp;gt;
          &amp;lt;Text&amp;gt;{post.title}&amp;lt;/Text&amp;gt;
          &amp;lt;Text&amp;gt;{post.body}&amp;lt;/Text&amp;gt;
        &amp;lt;/View&amp;gt;
      ))}
    &amp;lt;/View&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the Expo app:&lt;br&gt;
Run your Expo app using the following command:&lt;br&gt;
&lt;code&gt;expo start&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Unlocking Opportunities: Amazon Certifications and Their Benefits</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Thu, 07 Mar 2024 12:29:01 +0000</pubDate>
      <link>https://dev.to/angela300/unlocking-opportunities-amazon-certifications-and-their-benefits-3ong</link>
      <guid>https://dev.to/angela300/unlocking-opportunities-amazon-certifications-and-their-benefits-3ong</guid>
      <description>&lt;p&gt;In the ever-evolving landscape of e-commerce and cloud computing, Amazon stands as a titan, continuously shaping industries and driving innovation. Amazon Web Services (AWS), in particular, has revolutionized the way businesses operate in the digital realm. With its vast array of services and solutions, AWS has become the backbone of countless organizations worldwide. To navigate this dynamic ecosystem effectively and capitalize on its full potential, individuals are turning to Amazon certifications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Amazon Certifications
&lt;/h3&gt;

&lt;p&gt;Amazon offers a comprehensive range of certifications designed to validate expertise and proficiency in various AWS technologies. These certifications cater to individuals at different stages of their careers, from beginners to seasoned professionals, covering a broad spectrum of roles such as architects, developers, sysops administrators, and more.&lt;/p&gt;

&lt;p&gt;The certification paths typically include foundational, associate, professional, and specialty levels, each targeting specific skill sets and knowledge domains. They cover essential topics like cloud computing concepts, security best practices, networking fundamentals, database management, machine learning, and beyond.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of Amazon Certifications
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Validation of Expertise
&lt;/h4&gt;

&lt;p&gt;Amazon certifications serve as tangible proof of one's skills and knowledge in AWS technologies. They are recognized globally and endorsed by industry leaders, making them invaluable assets for individuals seeking career advancement or transition into roles that demand AWS proficiency.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Career Advancement
&lt;/h4&gt;

&lt;p&gt;In today's competitive job market, possessing Amazon certifications can significantly enhance career prospects. Employers actively seek candidates with AWS expertise to drive digital transformation initiatives, manage cloud infrastructure, optimize performance, and ensure security and compliance.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Enhanced Credibility
&lt;/h4&gt;

&lt;p&gt;Earning an Amazon certification demonstrates a commitment to professional development and continuous learning. It instills confidence in employers, clients, and peers, showcasing an individual's dedication to mastering AWS services and staying abreast of industry trends and best practices.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Expanded Opportunities
&lt;/h4&gt;

&lt;p&gt;With the widespread adoption of AWS across diverse industries, certified professionals have access to a myriad of job opportunities globally. Whether it's in technology, finance, healthcare, retail, or any other sector, AWS skills are in high demand, opening doors to exciting career paths and lucrative roles.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Higher Earning Potential
&lt;/h4&gt;

&lt;p&gt;Professionals with Amazon certifications often command higher salaries compared to their non-certified counterparts. The specialized skills and expertise acquired through certification training translate into added value for employers, justifying premium compensation packages.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. Stay Ahead of the Curve
&lt;/h4&gt;

&lt;p&gt;AWS continually introduces new services, features, and updates to its platform. By pursuing Amazon certifications, individuals stay ahead of the curve, acquiring the latest knowledge and skills required to leverage cutting-edge technologies and drive innovation within their organizations.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Benefit from Amazon Certifications
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Identify Your Career Goals:
&lt;/h4&gt;

&lt;p&gt;Before embarking on an Amazon certification journey, assess your career aspirations and determine which certification aligns with your objectives. Whether you aim to become a cloud architect, developer, data engineer, or security specialist, choose a certification path that best suits your interests and expertise.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Invest in Training and Preparation:
&lt;/h4&gt;

&lt;p&gt;Preparation is key to success in earning Amazon certifications. Leverage various training resources provided by AWS, including official study guides, online courses, practice exams, and hands-on labs. Additionally, consider enrolling in accredited training programs or joining study groups to enhance your learning experience and gain practical insights from industry experts.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Hands-On Experience:
&lt;/h4&gt;

&lt;p&gt;Gain practical experience by working on real-world projects and experimenting with AWS services in a sandbox environment. Hands-on practice not only reinforces theoretical concepts but also enhances problem-solving skills and confidence in navigating the AWS platform.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Schedule and Take the Exam:
&lt;/h4&gt;

&lt;p&gt;Once you feel adequately prepared, schedule your certification exam through the AWS Training and Certification portal. Be sure to review the exam blueprint, understand the format and objectives, and familiarize yourself with the exam environment. On the day of the exam, remain calm, focused, and manage your time effectively to maximize your chances of success.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Continuous Learning and Renewal:
&lt;/h4&gt;

&lt;p&gt;AWS certifications require periodic renewal to ensure that certified professionals stay current with evolving technologies and best practices. Stay engaged with the AWS community, participate in forums, webinars, and events, and pursue advanced certifications to further enhance your skills and maintain your competitive edge in the industry.&lt;/p&gt;

&lt;p&gt;How do you best prepare for an amazon certification exam? &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Understand the Exam Blueprint:&lt;br&gt;
Each AWS certification exam has a detailed blueprint outlining the topics covered, weighting of each domain, and the skills assessed. You need to familiarize yourself with the exam blueprint to understand the scope of the exam and prioritize your study efforts accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the Right Study Materials:&lt;br&gt;
Utilize a variety of study materials, including official AWS documentation, whitepapers, online courses, practice exams, and books authored by industry experts. AWS offers comprehensive training resources through the AWS Training and Certification portal, including free digital training courses and paid instructor-led training options.&lt;br&gt;
Utilize the free digital training courses offered by AWS before attempting your exam, as they are highly informative and closely aligned with the exam content. These courses provide valuable insights and cover topics that are similar to those you'll encounter in the exam, helping you to familiarize yourself with the material and increase your chances of success.&lt;br&gt;
For example: Before taking on a Solutions Architect Beginner certification, I’ld first complete related courses on AWS skill builder, &lt;a href="https://explore.skillbuilder.aws/"&gt;https://explore.skillbuilder.aws/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hands-On Practice:&lt;br&gt;
Practical experience is crucial for mastering AWS concepts and services. Set up a free AWS account or utilize AWS Free Tier to experiment with different services, build projects, and solve real-world scenarios. Hands-on practice not only reinforces theoretical knowledge but also helps you become proficient in navigating the AWS Management Console and using AWS CLI (Command Line Interface).&lt;br&gt;
Amazon certifications offer a gateway to a world of opportunities in the rapidly expanding realm of cloud computing. Whether you're a seasoned IT professional or a novice looking to break into the field, investing in Amazon certifications can propel your career to new heights, unlock doors to exciting roles, and position you as a trusted expert in AWS technologies. Embrace the journey of continuous learning, and let Amazon certifications be your passport to success in the digital age.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Best Hosting Techniques for 2024</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Thu, 07 Mar 2024 09:42:22 +0000</pubDate>
      <link>https://dev.to/angela300/best-hosting-techniques-for-2024-28mn</link>
      <guid>https://dev.to/angela300/best-hosting-techniques-for-2024-28mn</guid>
      <description>&lt;p&gt;Hello there good morning! In today's digital era, deploying web applications has become an essential step in bringing your ideas to life. With the rise of frameworks like React, Vue.js, and Angular, you have a plethora of options for hosting their applications. However, choosing the right hosting platform can be daunting, especially with the evolving landscape of technology and services. In this article, I will explore the best hosting techniques for 2024, focusing primarily on deploying React applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction to React Hosting&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React, a popular JavaScript library for building user interfaces, has gained immense traction in recent years due to its component-based architecture and virtual DOM rendering. Deploying React applications involves serving static files or integrating with backend services, depending on the project's requirements. In 2024, you have access to numerous hosting platforms, each offering unique features and capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Vercel:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vercel stands out as a top choice for deploying React applications, particularly those built with Next.js. With seamless integration and support for serverless functions, Vercel simplifies the deployment process. Its hobby plan is free, making it accessible for you to get started quickly.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment using the Vercel CLI:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Vercel globally using npm.&lt;/li&gt;
&lt;li&gt;Authenticate with your account using &lt;code&gt;vercel login&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Navigate to your project directory and deploy using &lt;code&gt;vercel&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Follow the prompts to configure your deployment settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Firebase:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Firebase, a product of Google, offers a comprehensive development platform with hosting capabilities. While Firebase is known for its real-time database and authentication services, its hosting feature provides a robust solution for deploying React applications. The Spark plan is free, making it suitable for small to medium-sized projects.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment using the Firebase CLI:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Firebase CLI globally using npm.&lt;/li&gt;
&lt;li&gt;Authenticate with your Firebase or Google account using &lt;code&gt;firebase login&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Initialize your project using &lt;code&gt;firebase init&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Build your React project using &lt;code&gt;npm run build&lt;/code&gt; and deploy using &lt;code&gt;firebase deploy&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Netlify:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Netlify offers a modern workflow for building and deploying web applications, including React apps. With features like continuous deployment from Git repositories and serverless functions, Netlify streamlines the deployment process. Its free starter plan makes it an attractive option for you.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment using the Netlify CLI:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build your project using &lt;code&gt;npm run build&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Install Netlify CLI globally using npm.&lt;/li&gt;
&lt;li&gt;Link your project to a site using &lt;code&gt;netlify init&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Specify the build directory and deploy using &lt;code&gt;netlify deploy&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. GitHub Pages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GitHub Pages provides static site hosting directly integrated into the GitHub platform. While it's ideal for simple static websites, it lacks support for server-side code. However, for hosting open-source projects, GitHub Pages offers a free solution.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment with GitHub Pages:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a repository for your project on GitHub.&lt;/li&gt;
&lt;li&gt;Initialize the repository, add your files, and commit changes.&lt;/li&gt;
&lt;li&gt;Set up the homepage field in your &lt;code&gt;package.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Deploy your app using &lt;code&gt;npm run deploy&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Surge:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Surge offers a simple command-line interface for publishing web applications. While it's limited to static webpages, Surge's ease of use makes it a convenient choice for deploying React apps. Its free basic plan caters to you on a budget.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment using the Surge CLI:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build your project using &lt;code&gt;npm run build&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Install Surge CLI globally using npm.&lt;/li&gt;
&lt;li&gt;Navigate to the build directory and deploy using &lt;code&gt;surge&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Render:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Render, a fully managed cloud platform, offers seamless deployment directly from Git repositories. While it's relatively new compared to other platforms, Render provides features like private services and automatic HTTPS. Its free individual plan makes it accessible for you.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment using the Render dashboard:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an account on Render and connect your Git repository.&lt;/li&gt;
&lt;li&gt;Configure your project settings and deploy from the dashboard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;7. GitLab Pages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GitLab Pages allows you to build, test, and deploy static websites directly from a GitLab repository. With continuous deployment and custom domains support, GitLab Pages caters to all users within the GitLab ecosystem.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment with GitLab Pages:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a repository on GitLab for your project.&lt;/li&gt;
&lt;li&gt;Initialize the repository, add your files, and commit changes.&lt;/li&gt;
&lt;li&gt;Set up the homepage field in your &lt;code&gt;package.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Configure CI/CD using a &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file and deploy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;8. AWS Amplify:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AWS Amplify, a development platform from Amazon Web Services, enables quick deployment of mobile and web applications. While it offers a wide range of features, including authentication and APIs, AWS Amplify may be more complex compared to other platforms. Its free tier provides you with a starting point for hosting React apps.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment using the AWS Amplify CLI:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the AWS Amplify CLI globally using npm.&lt;/li&gt;
&lt;li&gt;Configure your project and initialize Amplify.&lt;/li&gt;
&lt;li&gt;Deploy your React app using &lt;code&gt;amplify publish&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;9. Cloudflare Pages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cloudflare Pages, a JAMstack platform, offers seamless integration with GitHub repositories for deploying web applications. While it focuses on frontend development, Cloudflare Pages provides fast and easy deployment of React apps. Its free plan and it does greatly help when seeking a hassle-free hosting solution.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Deployment using the Cloudflare CLI:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the create-cloudflare package globally using npm.&lt;/li&gt;
&lt;li&gt;Configure your project and deploy to Cloudflare Pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By choosing the right hosting solution based on project requirements and budget, you can bring their React applications to production with ease. Whether it's a small personal project or a large-scale application, the hosting techniques discussed in this article provide you with the flexibility and scalability needed to succeed in today's digital landscape.&lt;/p&gt;

&lt;p&gt;Just before you leave, if you enjoy exploring programming on different and creative paradigms, you can share it on Belleapp...&lt;a href="//belleapp-79fb4.firebaseapp.com"&gt;&lt;/a&gt; &lt;a href="https://belleapp-79fb4.firebaseapp.com/"&gt;https://belleapp-79fb4.firebaseapp.com/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Your first Django app with ReactJs frontend</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Thu, 15 Feb 2024 17:51:41 +0000</pubDate>
      <link>https://dev.to/angela300/your-first-django-app-with-reactjs-frontend-2nc</link>
      <guid>https://dev.to/angela300/your-first-django-app-with-reactjs-frontend-2nc</guid>
      <description>&lt;p&gt;ReactJS is a popular JavaScript library used for building user interfaces, and Django is a high-level Python web framework that is widely used for building web applications. Connecting these two powerful tools can produce a robust web application.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will learn how to connect ReactJS and Django Framework using A Hello World! application.&lt;/p&gt;

&lt;p&gt;Make sure you already have Node.js and Python installed on your system&lt;/p&gt;

&lt;p&gt;On your vs code terminal, open a new window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018681029%2F9e5875f2-21c7-4168-bd82-c394c98e3c72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018681029%2F9e5875f2-21c7-4168-bd82-c394c98e3c72.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open a new terminal and navigate to the desktop.&lt;/p&gt;

&lt;p&gt;Run this command,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;django-admin startproject myproject&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you got this error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018730452%2Fdf756177-2ea9-4b08-bf06-70384d64e593.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018730452%2Fdf756177-2ea9-4b08-bf06-70384d64e593.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Activate Virtual Environment (if applicable). If you're working within a virtual environment, make sure it's activated. You can activate it by running:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pipenv shell&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018819336%2F808317a0-7957-4d48-9dce-4afdb4d6593e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018819336%2F808317a0-7957-4d48-9dce-4afdb4d6593e.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the error is solved, now run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;django-admin startproject myproject&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create a new directory called &lt;strong&gt;myproject&lt;/strong&gt; which will have the basic structure of a Django project.&lt;/p&gt;

&lt;p&gt;Create a new React application in the myproject directory using the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app myapp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Install Required Packages&lt;/p&gt;

&lt;p&gt;Once the project and application are created, we need to install some packages. For Django,  install Django Rest Framework and Django Cors Headers. For React, install Axios for making HTTP requests.&lt;/p&gt;

&lt;p&gt;To install Django Rest Framework and Django Cors Headers, run the following command in the myproject directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install djangorestframework django-cors-headers&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To install Axios, run the following command inside the myapp directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install axios&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Build the API Endpoints in Django&lt;/p&gt;

&lt;p&gt;After installing the required packages, we can start building the API endpoints in Django. Create a new Django app to handle the API requests. The API endpoint will return JSON data when we make HTTP requests to it. We can use Django Rest Framework to build the API endpoints.&lt;/p&gt;

&lt;p&gt;To create a new Django app, run the following command inside the myproject directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python&lt;/code&gt; &lt;a href="http://manage.py" rel="noopener noreferrer"&gt;&lt;code&gt;manage.py&lt;/code&gt;&lt;/a&gt; &lt;code&gt;startapp myapi&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your directory now looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018930561%2F3be3ebd1-d9bf-4b1c-a41c-166acf53d662.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708018930561%2F3be3ebd1-d9bf-4b1c-a41c-166acf53d662.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The new directory called myapi has the basic structure of a Django app.&lt;/p&gt;

&lt;p&gt;Next, Open the &lt;a href="http://settings.py" rel="noopener noreferrer"&gt;settings.py&lt;/a&gt; file inside the myproject directory and add the following lines of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSTALLED_APPS = [
    'rest_framework',
    'corsheaders',
    'myapi',
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These lines of code will add the rest_framework, corsheaders, and myapi apps to the INSTALLED_APPS list, add the CorsMiddleware to the MIDDLEWARE list, and allow all origins to make cross-origin requests.&lt;/p&gt;

&lt;p&gt;When we try to make an HTTP request from a different origin (e.g., from the React app to the Django API), we may run into a CORS error. To fix this, we need to add the Django Cors Headers package to the Django project. This package will add the necessary headers to allow cross-origin requests.&lt;/p&gt;

&lt;p&gt;Next, open the &lt;a href="http://views.py" rel="noopener noreferrer"&gt;views.py&lt;/a&gt; file inside the myapi directory and add the following lines of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(['GET'])
def hello_world(request):
    return Response({'message': 'Hello, world!'})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a new API endpoint that returns a JSON response with the message “Hello, world!”.&lt;/p&gt;

&lt;p&gt;Add URLs :&lt;/p&gt;

&lt;p&gt;Open the &lt;a href="http://urls.py" rel="noopener noreferrer"&gt;urls.py&lt;/a&gt; inside the myproject directory and add these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('myapi.urls'))
]
Finally, Create the urls.py file inside the myapi directory and add the following lines of code:
from django.urls import path
from . import views

urlpatterns = [
    path('hello-world/', views.hello_world, name='hello_world'),
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a new URL pattern that maps to the hello_world function in &lt;a href="http://views.py" rel="noopener noreferrer"&gt;views.py&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next, We  will create a React component that makes HTTP requests to the API endpoints. We will use Axios to make the HTTP requests. Once we receive the JSON data, we can display it on the web page using React components.&lt;/p&gt;

&lt;p&gt;Create a new file called HelloWorld.js inside the src directory of the myapp directory, and add the following lines of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import axios from 'axios';

function HelloWorld() {
  const [message, setMessage] = useState('');

  useEffect(() =&amp;gt; {
    axios.get('http://localhost:8000/hello-world/')
      .then(response =&amp;gt; {
        setMessage(response.data.message);
      })
      .catch(error =&amp;gt; {
        console.log(error);
      });
  }, []);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;{message}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default HelloWorld;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a new React component called HelloWorld that makes an HTTP GET request to the hello-world API endpoint we defined earlier. The response data is stored in the message state, which is displayed on the web page.&lt;/p&gt;

&lt;p&gt;Finally, we will now render the HelloWorld component inside the App.js file in the src directory of the myapp directory. Replace the contents of App.js with the following lines of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;HelloWorld /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code renders the HelloWorld component inside the div element with the root ID.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To run the project,&lt;/strong&gt; open two terminal windows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the first window,&lt;/strong&gt; navigate to the myproject directory and run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python&lt;/code&gt; &lt;a href="http://manage.py" rel="noopener noreferrer"&gt;&lt;code&gt;manage.py&lt;/code&gt;&lt;/a&gt; &lt;code&gt;runserver&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will start the Django development server.&lt;/p&gt;

&lt;p&gt;In the second window, navigate to the myapp directory and run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will start the React development server.&lt;/p&gt;

&lt;p&gt;Open your web browser and navigate to &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/&lt;/a&gt;. You should see the message &lt;strong&gt;"Hello, world!"&lt;/strong&gt; displayed on the web page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708019319158%2F5812fb79-8170-479b-9d17-85429b631b49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708019319158%2F5812fb79-8170-479b-9d17-85429b631b49.png"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A wordpress plugin to add daily tasks to your website</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Wed, 31 Jan 2024 10:09:05 +0000</pubDate>
      <link>https://dev.to/angela300/a-wordpress-plugin-to-add-daily-tasks-to-your-website-39p3</link>
      <guid>https://dev.to/angela300/a-wordpress-plugin-to-add-daily-tasks-to-your-website-39p3</guid>
      <description>&lt;p&gt;&lt;strong&gt;With Chatgpt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On chatgpt, type this request:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create the code for a wordpress plugin that adds a 'Daily task' window to the wordpress dashboard. The Daily Task window should be writable and it should be able to check all done tasks when a user is finished with a specific task&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a new directory for your plugin. Let's name it daily-task-widget.&lt;/p&gt;

&lt;p&gt;Inside the daily-task-widget directory, create a main plugin file named daily-task-widget.php with the PHP code that is generated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
/*
Plugin Name: Daily Task Widget
Description: Adds a daily task widget to the WordPress dashboard.
Version: 1.1
Author: Your Name
*/

// Enqueue jQuery
function enqueue_jquery() {
    wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'enqueue_jquery');

// Add the widget to the dashboard
function daily_task_widget() {
    wp_add_dashboard_widget(
        'daily_task_widget',
        'Daily Task',
        'display_daily_task_widget'
    );
}

// Display the widget content
function display_daily_task_widget() {
    $tasks = get_user_meta(get_current_user_id(), 'daily_tasks',
 true);
    ?&amp;gt;
    &amp;lt;textarea id="daily_tasks" name="daily_tasks" 
    style="width: 100%;" rows="5"&amp;gt;&amp;lt;?php echo esc_textarea($tasks); ?&amp;gt;
&amp;lt;/textarea&amp;gt;
    &amp;lt;br&amp;gt;
    &amp;lt;label for="task_done"&amp;gt;
    Mark task as done:
    &amp;lt;input type="checkbox" id="task_done" name="task_done"&amp;gt;&amp;lt;/label&amp;gt;
    &amp;lt;button id="save_tasks"&amp;gt;Save Tasks&amp;lt;/button&amp;gt;

    &amp;lt;script&amp;gt;
        jQuery(document).ready(function($) {
            $('#save_tasks').on('click', function() {
                var tasks = $('#daily_tasks').val();
                var taskDone = 
                $('#task_done').is(':checked') ? 1 : 0;

                $.post(ajaxurl, {
                    action: 'save_daily_tasks',
                    tasks: tasks,
                    task_done: taskDone,
                    security: 
           '&amp;lt;?php echo wp_create_nonce("save_daily_tasks_nonce"); ?&amp;gt;'
                }, function(response) {
                    alert('Tasks saved successfully!');
                });
            });
        });
    &amp;lt;/script&amp;gt;
    &amp;lt;?php
}

// Save the tasks when the user updates the dashboard
function save_daily_tasks() {
    check_ajax_referer('save_daily_tasks_nonce', 'security');

    if (isset($_POST['tasks'])) {
        $tasks = sanitize_textarea_field($_POST['tasks']);
        update_user_meta(get_current_user_id(), 
        'daily_tasks', $tasks);
    }

    if (isset($_POST['task_done'])) {
        // Handle marking task as done
        // You can implement your logic here
    }

    wp_die();
}

// Hook functions to WordPress actions
add_action('wp_dashboard_setup', 'daily_task_widget');
add_action('wp_ajax_save_daily_tasks', 'save_daily_tasks');
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This simple plugin adds a textarea for daily tasks and a checkbox to mark a task as done. The tasks are saved in the user's meta data using the update_user_meta function.&lt;/p&gt;

&lt;p&gt;Zip the daily-task-widget directory.&lt;/p&gt;

&lt;p&gt;Upload the zipped file through the WordPress admin interface or manually upload it to the wp-content/plugins directory on your server.&lt;/p&gt;

&lt;p&gt;Activate the plugin through the WordPress admin.&lt;/p&gt;

&lt;p&gt;Now, when users log in, they will see a "Daily Task" widget on their dashboard where they can write and save their daily tasks. Note that this is a basic example, and you may want to enhance it based on your specific requirements.&lt;/p&gt;

&lt;p&gt;Thanks for reading through! To support my blog you can make a donation through &lt;a href="https://www.buymeacoffee.com/angela300"&gt;https://www.buymeacoffee.com/angela300&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Whasapp Web Clone with Google authentication and firebase</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Tue, 30 Jan 2024 14:54:50 +0000</pubDate>
      <link>https://dev.to/angela300/whasapp-web-clone-3460</link>
      <guid>https://dev.to/angela300/whasapp-web-clone-3460</guid>
      <description>&lt;p&gt;This app is build with React JS for Beginners.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functionalities implemented:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Send a message&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Receive a message&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new room&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Login with Google&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Switch between different rooms&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tech Stack Implemented&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ReactJS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Firebase Firestore Realtime db&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Materials UI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React Router&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React Context API&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google Authentication&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy using Firebase&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inside your desktop on your pc, run the command to create a react app:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app whatsappwebclone&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Set up&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;-&lt;strong&gt;Firebase set up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="http://firebase.com"&gt;firebase.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to console&lt;/p&gt;

&lt;p&gt;Click on ‘Add new project’&lt;/p&gt;

&lt;p&gt;Type the project name as ‘Whats app Clone’&lt;/p&gt;

&lt;p&gt;Click on ‘Continue’, the click on ‘Continue’ again&lt;/p&gt;

&lt;p&gt;Select default account for Firebase&lt;/p&gt;

&lt;p&gt;Click on, ‘Create project’&lt;/p&gt;

&lt;p&gt;On the project overview on a screen that looks like show below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QDe8O-8K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706618065117/f35488e7-c265-4d7c-be26-bdb31992a284.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QDe8O-8K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706618065117/f35488e7-c265-4d7c-be26-bdb31992a284.png" alt="" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on ‘Project settings’ under the settings icon&lt;/p&gt;

&lt;p&gt;Sroll to the bottom of the page and click on this icon: &amp;lt;/&amp;gt;&lt;/p&gt;

&lt;p&gt;As shown below, Add an App nickname, click on ‘Also set up Firebase hosting for this app’, and then click on ‘Register App’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BMilvbBu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706618260988/725a0196-7b30-42a8-bd15-bf5b742f94a5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BMilvbBu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706618260988/725a0196-7b30-42a8-bd15-bf5b742f94a5.png" alt="" width="727" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on ‘next’&lt;/p&gt;

&lt;p&gt;Run this code on your vs code terminal on the app’s root folder:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g firebase-tools&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Click on ‘next’&lt;/p&gt;

&lt;p&gt;Click on ‘continue to console’&lt;/p&gt;

&lt;p&gt;At the bottom of the page, click on the switch, ‘Config’:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yVOWXfil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706618347888/03505a27-8ff0-4c91-8254-9a97c65f9276.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yVOWXfil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706618347888/03505a27-8ff0-4c91-8254-9a97c65f9276.png" alt="" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy that code&lt;/p&gt;

&lt;p&gt;In your App’s src folder, create a new file ‘firebase.js’, and paste the code on the file.&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;Other App set up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To start the app, on your terminal run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Delete the following files from your App’s folder files:&lt;/p&gt;

&lt;p&gt;Logo.svg&lt;/p&gt;

&lt;p&gt;App.test.js&lt;/p&gt;

&lt;p&gt;setUpTests.js&lt;/p&gt;

&lt;p&gt;Remove the code in App.js and replace it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Let's build a whatsapp Clone&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete everything in App.css&lt;/p&gt;

&lt;p&gt;In index.css, add this code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
  margin: 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To name components in our app, we will be using the ‘BEM naming convention’, which is a very easy way of naming components in react.&lt;/p&gt;

&lt;p&gt;In App.js, we will have a div of className, app_body, and has the components, sidebar and chat&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Let's build a whatsapp Clone&amp;lt;/h1&amp;gt;
      &amp;lt;div className="app_body"&amp;gt;
        {/* Sidebar */}
        {/* Chat */}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In App.css, add this code to style the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.App {
  display: grid;
  place-items: center;
  background-color: #dadbd3;
  height: 100vh;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To style the div with className ‘app_body’, add this code to App.css too,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.app_body{
  display: flex;
  background-color: #ededed;
  height: 90vh;
  width: 90vw;
  box-shadow: -1px 4px 20px -6px rgba(0, 0, 0, 0.2);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In src folder, create a new folder called sidebar.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'

function Sidebar() {
  return (
    &amp;lt;div&amp;gt;Sidebar&amp;lt;/div&amp;gt;
  )
}

export default Sidebar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Sidebar.js, go ahead and import the corresponding css file,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import ‘./Sidebar.css’&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create a new file in src folder, Sidebar.css&lt;/p&gt;

&lt;p&gt;Edit sidebar.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Sidebar() {
  return (
    &amp;lt;div className="sidebar"&amp;gt;
        &amp;lt;h1&amp;gt;Sidebar&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit the div of className App in App.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;div className="App"&amp;gt;
      &amp;lt;div className="app_body"&amp;gt;
        &amp;lt;Sidebar/&amp;gt;
        {/* Chat */}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also in App.js, add this line:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import Sidebar from './sidebar';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Edit Sidebar.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import "./Sidebar.css"

const Sidebar = () =&amp;gt; {
    return (
        &amp;lt;div className="sidebar"&amp;gt;
            &amp;lt;div className="sidebar_header"&amp;gt;

            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_search"&amp;gt;

            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_chats"&amp;gt;

            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Sidebar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need some icons, so we will need to install Material UI:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @material-ui/core&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Also run this code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @material-ui/icons&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Edit Sidebar.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import "./Sidebar.css"
import { Avatar } from "@material-ui/core"
import { DonutLarge } from '@material-ui/icons'
import { Chat } from '@material-ui/icons'
import { MoreVert } from '@material-ui/icons'

const Sidebar = () =&amp;gt; {
    return (
        &amp;lt;div className="sidebar"&amp;gt;
            &amp;lt;div className="sidebar_header"&amp;gt;
                &amp;lt;Avatar /&amp;gt;
                &amp;lt;div className="sidebar_headerRight"&amp;gt;
                    &amp;lt;DonutLarge /&amp;gt;
                    &amp;lt;Chat /&amp;gt;
                    &amp;lt;MoreVert /&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_search"&amp;gt;

            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_chats"&amp;gt;

            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Sidebar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit your Sidebar.css to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.sidebar {
    flex: 0.35;
}
.sidebar_header {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    border-right: 1px solid lightgray;
}

.sidebar_headerRight{
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 10vw;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, your application's appearance should resemble the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ltWHkcji--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706619199472/04a57967-75c3-40b2-ba52-f8b2ea948093.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ltWHkcji--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706619199472/04a57967-75c3-40b2-ba52-f8b2ea948093.png" alt="" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Proceed with the build …&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Edit Sidebar.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import "./Sidebar.css"
import { Avatar, IconButton } from "@material-ui/core"
import { DonutLarge, SearchOutlined } from '@material-ui/icons'
import { Chat } from '@material-ui/icons'
import { MoreVert } from '@material-ui/icons'
import SidebarChat from './SidebarChat'

const Sidebar = () =&amp;gt; {
    return (
        &amp;lt;div className="sidebar"&amp;gt;
            &amp;lt;div className="sidebar_header"&amp;gt;
                &amp;lt;Avatar /&amp;gt;
                &amp;lt;div className="sidebar_headerRight"&amp;gt;
                    &amp;lt;IconButton className="MuiSvgIcon-root"&amp;gt;
                        &amp;lt;DonutLarge /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton className="MuiSvgIcon-root"&amp;gt;
                        &amp;lt;Chat /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton className="MuiSvgIcon-root"&amp;gt;
                        &amp;lt;MoreVert /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_search"&amp;gt;
                &amp;lt;div className="sidebar_searchContainer"&amp;gt;
                    &amp;lt;SearchOutlined/&amp;gt;
                    &amp;lt;input placeholder="Search or start new chat" type="text"/&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_chats"&amp;gt;
                &amp;lt;SidebarChat/&amp;gt;
                &amp;lt;SidebarChat/&amp;gt;
                &amp;lt;SidebarChat/&amp;gt;
                &amp;lt;SidebarChat/&amp;gt;
                &amp;lt;SidebarChat/&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Sidebar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the src folder, add these to files:&lt;/p&gt;

&lt;p&gt;‘SidebarChat.js’ and ‘SidebarChat.css’&lt;/p&gt;

&lt;p&gt;- SidebarChat.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import './SidebarChat.css'

const SidebarChat = () =&amp;gt; {
  return (
    &amp;lt;div className="sidebarChat"&amp;gt;
        &amp;lt;h1&amp;gt;hey&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default SidebarChat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit sidebar.css to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.sidebar {
    display: flex;
    flex-direction: column;
    flex: 0.35;
}
.sidebar_search {
    display: flex;
    align-items: center;
    background-color: #f6f6f6;
    height: 39px;
    padding: 10px;
}
.sidebar_searchContainer{
    display: flex;
    align-items: center;
    background-color: white;
    width: 100%;
    height: 35px;
    border-radius: 20px;
    padding-left: 5px;
}
.sidebar_searchContainer &amp;gt; .MuiSvgIcon-root{
    color: grey;
    padding: 10;
}
.sidebar_searchContainer &amp;gt; input {
    border: none;
    margin-left: 10px;
}
.sidebar_header {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    border-right: 1px solid lightgray;
}

.sidebar_headerRight{
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 10vw;
}

.sidebar_headerRight &amp;gt;.MuiSvgIcon-root{
    margin-right: 2vw;
    font-size: 24px !important;
}

.sidebar_chats{
    flex: 1;
    background-color: white;
    overflow: scroll;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we are going to add some avatars:&lt;/p&gt;

&lt;p&gt;We will use an endpoint that gives you a random avatar&lt;/p&gt;

&lt;p&gt;Edit SidebarChat.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import './SidebarChat.css'
import { Avatar } from '@material-ui/core'

const SidebarChat = () =&amp;gt; {
  return (
    &amp;lt;div className="sidebarChat"&amp;gt;
        &amp;lt;Avatar 
src="https://api.dicebear.com/
7.x/adventurer/svg?seed=Fel675gfcedsix667"/&amp;gt;
        &amp;lt;div className="sidebarChat_info"&amp;gt;
            &amp;lt;h2&amp;gt;Room name&amp;lt;/h2&amp;gt;
            &amp;lt;p&amp;gt;Last message...&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default SidebarChat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You notice we added Avatar as this,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Avatar src="&lt;/code&gt;&lt;a href="https://api.dicebear.com/7.x/adventurer/svg?seed=Fel675gfcedsix667%22/"&gt;&lt;code&gt;https://api.dicebear.com/7.x/adventurer/svg?seed=Fel675gfcedsix667"/&lt;/code&gt;&lt;/a&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We will make use of a UseEffect hook to generate a new avatar each time the Api is loaded/called:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const [seed, setSeed] = useState('');
    useEffect(()=&amp;gt;{
        setSeed(Math.floor(Math.random()*5000))
    }, [])
  return (
    &amp;lt;div className="sidebarChat"&amp;gt;
        &amp;lt;Avatar src=
{`https://api.dicebear.com/7.x/adventurer/svg?seed=${seed}`}/&amp;gt;
        &amp;lt;div className="sidebarChat_info"&amp;gt;
            &amp;lt;h2&amp;gt;Room name&amp;lt;/h2&amp;gt;
            &amp;lt;p&amp;gt;Last message...&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will go ahead and make this accept some prompts.&lt;/p&gt;

&lt;p&gt;Add this to SidebarChat.css,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.sidebarChat {
    display: flex;
    padding: 20px;
    cursor: pointer;
    border-bottom: 1px solid #f6f6f6;
}

.sidebarChat:hover{
    background-color: #ebebeb;
}

.sidebarChat_info &amp;gt; h2 {
    font-size: 16px;
    margin-bottom: 8px;
}

.sidebarChat_info{
    margin-left: 15px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have added a new prop, addNewChat in SidebarChat,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const SidebarChat = ({ addNewChat }) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then in Sidebar.js, we have,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;SidebarChat addNewChat/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In SidebarChat.js, before we return our jsx, we will have:&lt;/p&gt;

&lt;p&gt;If !addNewChat, we have SidebarChat.js show the normal stuff. Otherwise, it will render a div with a className of SidebarChat, and when clicked, it will execute some function to createChat.&lt;/p&gt;

&lt;p&gt;By now, SidebarChat.js looks like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import './SidebarChat.css'
import { Avatar } from '@material-ui/core'
import { useEffect } from 'react'
import { useState } from 'react'

const SidebarChat = ({ addNewChat }) =&amp;gt; {
    const [seed, setSeed] = useState('');
    useEffect(()=&amp;gt;{
        setSeed(Math.floor(Math.random()*5000))
    }, [])

    const createChat = () =&amp;gt; {
        const roomName = prompt("Please enter name for chat")

        if(roomName) {
            //do some clever stuff in database
        }
    }

  return !addNewChat ? (
    &amp;lt;div className="sidebarChat"&amp;gt;
        &amp;lt;Avatar src=
{`https://api.dicebear.com/7.x/adventurer/svg?seed=${seed}`}/&amp;gt;
        &amp;lt;div className="sidebarChat_info"&amp;gt;
            &amp;lt;h2&amp;gt;Room name&amp;lt;/h2&amp;gt;
            &amp;lt;p&amp;gt;Last message...&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  ): (
    &amp;lt;div onClick={createChat}
    className="sidebarChat"&amp;gt;
        &amp;lt;h2&amp;gt;Add new Chat&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default SidebarChat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In App.js, lets now add the component, Chat&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;Chat /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Src folder, create two new files, Chat.js and Chat.css&lt;/p&gt;

&lt;p&gt;Chat.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import "./Chat.css"

const Chat = () =&amp;gt; {
  return (
    &amp;lt;div className="chat"&amp;gt;

    &amp;lt;/div&amp;gt;
  )
}

export default Chat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit Chat.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import "./Chat.css"
import { Avatar, IconButton } from '@material-ui/core'
import { useState, useEffect } from 'react'
import { AttachFile, MoreVert, SearchOutlined } 
from '@material-ui/icons'

const Chat = () =&amp;gt; {
    const [seed, setSeed] = useState('');
    useEffect(()=&amp;gt;{
        setSeed(Math.floor(Math.random()*5000))
    }, [])

    return (
        &amp;lt;div className="chat"&amp;gt;
            &amp;lt;div className="chat_header"&amp;gt;
                &amp;lt;Avatar src=
{`https://api.dicebear.com/7.x/adventurer/svg?seed=${seed}`}/&amp;gt;
                &amp;lt;div className="chat_headerInfo"&amp;gt;
                    &amp;lt;h3&amp;gt;Room name&amp;lt;/h3&amp;gt;
                    &amp;lt;p&amp;gt;Last seet at ...&amp;lt;/p&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="chat_headerRight"&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;SearchOutlined/&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;AttachFile/&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;MoreVert/&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="chat_body"&amp;gt;

            &amp;lt;/div&amp;gt;
            &amp;lt;div className="chat_footer"&amp;gt;

            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Chat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this to chat.css,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.chat {
    flex: 0.66;
}

.chat_header{
    padding: 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid lightgray;
}

.chat_headerInfo {
    flex: 1;
    padding-left: 20px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By now your app should appear like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RcUF0Nod--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706619873668/e7e0ea84-1ad6-4b4f-9166-21ceb40dfa33.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RcUF0Nod--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706619873668/e7e0ea84-1ad6-4b4f-9166-21ceb40dfa33.png" alt="" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By now, your chat.js file looks like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import "./Chat.css"
import { Avatar, IconButton } from '@material-ui/core'
import { useState, useEffect } from 'react'
import { AttachFile, MoreVert, SearchOutlined } 
from '@material-ui/icons'

const Chat = () =&amp;gt; {
    const [seed, setSeed] = useState('');
    useEffect(() =&amp;gt; {
        setSeed(Math.floor(Math.random() * 5000))
    }, [])

    return (
        &amp;lt;div className="chat"&amp;gt;
            &amp;lt;div className="chat_header"&amp;gt;
                &amp;lt;Avatar src=
{`https://api.dicebear.com/7.x/adventurer/svg?seed=${seed}`} /&amp;gt;
                &amp;lt;div className="chat_headerInfo"&amp;gt;
                    &amp;lt;h3&amp;gt;Room name&amp;lt;/h3&amp;gt;
                    &amp;lt;p&amp;gt;Last seet at ...&amp;lt;/p&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="chat_headerRight"&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;SearchOutlined /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;AttachFile /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;MoreVert /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="chat_body"&amp;gt;
                &amp;lt;p className=
{`chat_message ${true &amp;amp;&amp;amp; "chat_reciever"}`}&amp;gt;
                    &amp;lt;span className="chat_name"&amp;gt;Brown Tylor&amp;lt;/span&amp;gt;
                    Hey Guys
                    &amp;lt;span className="chat_timestamp"&amp;gt;3:52pm&amp;lt;/span&amp;gt;
                &amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="chat_footer"&amp;gt;

            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Chat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On this line of code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;p className={`chat_message ${true &amp;amp;&amp;amp; "chat_reciever"}`}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The chat_reciever class is added only if a certain condition is true.&lt;/p&gt;

&lt;p&gt;For the User who is signed in, this will be evaluated to true, hence their message will be green, as styled in chat.css:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U190QzQz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706619996245/7a111cfd-f4d9-46ff-9e58-08f6d659a797.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U190QzQz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706619996245/7a111cfd-f4d9-46ff-9e58-08f6d659a797.png" alt="" width="800" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chat.css:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.chat {
    flex: 0.65;
    display: flex;
    flex-direction: column;
}

.chat_header{
    padding: 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid lightgray;
}

.chat_headerInfo {
    flex: 1;
    padding-left: 20px;
}

.chat_headerInfo &amp;gt; h3 {
    margin-bottom: 3px;
    font-weight: 500;
}

.chat_headerInfo &amp;gt; p {
color: grey
}

.chat_message {
    position: relative;
    font-size: 16px;
    padding: 10px;
    border-radius: 10px;
    width: fit-content;
    background-color: #ffffff;
    margin-bottom: 30px;
}

.chat_reciever{
    margin-left: auto;
    background-color: #dcf8c6;
}

.chat_timestamp {
    margin-left: 10px;
    font-size: xx-small;
}

.chat_name {
    position: absolute;
    top: -15px;
    font-weight: 800;
    font-size: xx-small;
}

.chat_headerRight {
    display: flex;
    justify-content: space-between;
    min-width: 100px;
}

.chat_body {
    flex: 1;
    background-image: url("https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png");
    background-repeat: repeat;
    background-position: center;
    padding: 30px;
    overflow: scroll;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Chat.js now looks like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import "./Chat.css"
import { Avatar, IconButton } from '@material-ui/core'
import { useState, useEffect } from 'react'
import { AttachFile, InsertEmoticon, MoreVert, SearchOutlined, Mic }
 from '@material-ui/icons'

const Chat = () =&amp;gt; {
    const [seed, setSeed] = useState('');
    useEffect(() =&amp;gt; {
        setSeed(Math.floor(Math.random() * 5000))
    }, [])

    return (
        &amp;lt;div className="chat"&amp;gt;
            &amp;lt;div className="chat_header"&amp;gt;
                &amp;lt;Avatar src=
{`https://api.dicebear.com/7.x/adventurer/svg?seed=${seed}`} /&amp;gt;
                &amp;lt;div className="chat_headerInfo"&amp;gt;
                    &amp;lt;h3&amp;gt;Room name&amp;lt;/h3&amp;gt;
                    &amp;lt;p&amp;gt;Last seet at ...&amp;lt;/p&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="chat_headerRight"&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;SearchOutlined /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;AttachFile /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton&amp;gt;
                        &amp;lt;MoreVert /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="chat_body"&amp;gt;
                &amp;lt;p className=
{`chat_message ${true &amp;amp;&amp;amp; "chat_reciever"}`}&amp;gt;
                    &amp;lt;span className="chat_name"&amp;gt;Brown Tylor&amp;lt;/span&amp;gt;
                    Hey Guys
                    &amp;lt;span className="chat_timestamp"&amp;gt;3:52pm&amp;lt;/span&amp;gt;
                &amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="chat_footer"&amp;gt;
                &amp;lt;InsertEmoticon /&amp;gt;
                &amp;lt;form&amp;gt;
                    &amp;lt;input placeholder="Type a message" type="text"/&amp;gt;
                    &amp;lt;button type="submit"&amp;gt;Send a message&amp;lt;/button&amp;gt;
                &amp;lt;/form&amp;gt;
                &amp;lt;Mic /&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Chat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now add an onClick sendMessage function on the sendmessage button here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button onClick={sendMessage} type="submit"&amp;gt;Send a message&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just before the return statement on chat.js, we have the function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const sendMessage = (e) =&amp;gt; {

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to keep track of the message that the user is typing, so that when he/she pushes the enter key we can proceed to the next phase, like pushing to a database, etc. We keep track of the message by storing it in the state.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [input, setInput] = useState("");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then the value of our input variable will be the value set up in the useState,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input value={input} placeholder="Type a message" type="text"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each time the input changes, we need to fire off an an event to update the input value in the state with the latest user entry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input value={input} onChange={e =&amp;gt; setInput(e.target.Value)} 
placeholder="Type a message" type="text"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this sendMessage function,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const sendMessage = (e) =&amp;gt; {
        e.preventDefault();
        console.log('You typed &amp;gt;&amp;gt;&amp;gt;', input)
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;e.preventDefault ensures:&lt;/p&gt;

&lt;p&gt;By calling e.preventDefault(), you are telling the browser not to perform the default action associated with the form submission, which is typically a page reload. Instead, the custom behavior defined in the sendMessage function will be executed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setInput("");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;ensures the input is cleaned after pressing enter.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Adding firebase config&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now we will go ahead and add the Firebase config.&lt;/p&gt;

&lt;p&gt;Install Firebase with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i firebase&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create/Edit your firebase.js file to look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import { getAuth, GoogleAuthProvider } from 'firebase/auth';

const firebaseConfig = {
  apiKey: "AIzaSyDcHSKgEks5yWmdS6kb54US0KlbIXeIHR4",
  authDomain: "whats-app-clone-aac80.firebaseapp.com",
  projectId: "whats-app-clone-aac80",
  storageBucket: "whats-app-clone-aac80.appspot.com",
  messagingSenderId: "131021031275",
  appId: "1:131021031275:web:a8e2711178865ea927ae2e",
  measurementId: "G-RH8WL675D8"
};

const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);
const auth = getAuth(firebaseApp);
const provider = new GoogleAuthProvider();

export { auth, provider};
export default db;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open Firebase on your browser&lt;/p&gt;

&lt;p&gt;Click on Firestore database&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b9O783B0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706620567293/5b2a4d59-1516-4c78-ac89-5e8ef82b5cda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b9O783B0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706620567293/5b2a4d59-1516-4c78-ac89-5e8ef82b5cda.png" alt="" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;click on ‘Create Database’,&lt;/p&gt;

&lt;p&gt;Click on ‘next’,&lt;/p&gt;

&lt;p&gt;Click on ‘Start in test mode’, and click on ‘Enable’.&lt;/p&gt;

&lt;p&gt;Click on ‘Start collection’, and call it ‘rooms’, and populate it as follows, with field ‘name’, and value ‘Dance Room’:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uYsyWLE3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706620619092/87a410bd-2944-4a38-ac43-1c426e585088.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uYsyWLE3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706620619092/87a410bd-2944-4a38-ac43-1c426e585088.png" alt="" width="427" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on ‘Auto-ID’ at the top, and click on ‘save’.&lt;/p&gt;

&lt;p&gt;Click ‘Add Document’ to add a second room, populate it with Field ‘name’, and Value ‘Dev Room’, and save:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fgIWpeaA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706620684400/741fa99a-56a6-4d71-8ddb-c616e34a3a74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fgIWpeaA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706620684400/741fa99a-56a6-4d71-8ddb-c616e34a3a74.png" alt="" width="409" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s now connect the Sidebar to the database.&lt;/p&gt;

&lt;p&gt;In sidebar.js, add this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [rooms, setRooms] = useSatte([]);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then add a useEffect, for when the sidebar component loads, we want to show a piece of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    useEffect(()=&amp;gt; {

    }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above code says, perform this action once, when the sidebar component loads.&lt;/p&gt;

&lt;p&gt;Import db from firebase with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import db from './firebase'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Edit your sidebar.js and sidebarChat.js to appear as below:&lt;/p&gt;

&lt;p&gt;- Sidebar.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./Sidebar.css"
import React, { useState, useEffect } from 'react';
import { Avatar, IconButton } from '@material-ui/core';
import { DonutLarge, SearchOutlined, Chat, MoreVert } from 
'@material-ui/icons';
import SidebarChat from './SidebarChat';
import { db } from './firebase'; 
// Assuming your firebase.js exports the db instance
import { getFirestore, collection, onSnapshot } from 
'firebase/firestore';

const Sidebar = () =&amp;gt; {
    const [rooms, setRooms] = useState([]);

    useEffect(() =&amp;gt; {
        const fetchData = async () =&amp;gt; {
          const roomsCollection = collection(db, 'rooms');
          console.log('Rooms Collection:', roomsCollection); 
            // Log the rooms collection

          const unsubscribe = onSnapshot(roomsCollection, 
            (snapshot) =&amp;gt; {
            console.log('Snapshot received:', snapshot.docs);    
            // Log the snapshot data

            setRooms(
              snapshot.docs.map((doc) =&amp;gt; ({
                id: doc.id,
                data: doc.data(),
              }))
            );
          });

          return () =&amp;gt; {
            unsubscribe();
          };
        };

        fetchData();
      }, []);


    return (
        &amp;lt;div className="sidebar"&amp;gt;
            &amp;lt;div className="sidebar_header"&amp;gt;
                &amp;lt;Avatar /&amp;gt;
                &amp;lt;div className="sidebar_headerRight"&amp;gt;
                    &amp;lt;IconButton className="MuiSvgIcon-root"&amp;gt;
                        &amp;lt;DonutLarge /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton className="MuiSvgIcon-root"&amp;gt;
                        &amp;lt;Chat /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                    &amp;lt;IconButton className="MuiSvgIcon-root"&amp;gt;
                        &amp;lt;MoreVert /&amp;gt;
                    &amp;lt;/IconButton&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_search"&amp;gt;
                &amp;lt;div className="sidebar_searchContainer"&amp;gt;
                    &amp;lt;SearchOutlined /&amp;gt;
                    &amp;lt;input placeholder="Search or start new chat" 
                type="text" /&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="sidebar_chats"&amp;gt;
                &amp;lt;SidebarChat addNewChat /&amp;gt;
                {rooms.map(room =&amp;gt; (
                    &amp;lt;SidebarChat key={room.id} id={room.id} 
                        name={room.data.name} /&amp;gt;
                ))}
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default Sidebar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Sidebarchat.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import './SidebarChat.css'
import { Avatar } from '@material-ui/core'
import { useEffect } from 'react'
import { useState } from 'react'

const SidebarChat = ({ addNewChat, id, name }) =&amp;gt; {
    const [seed, setSeed] = useState('');
    useEffect(()=&amp;gt;{
        setSeed(Math.floor(Math.random()*5000))
    }, [])

    const createChat = () =&amp;gt; {
        const roomName = prompt("Please enter name for chat")

        if(roomName) {
            //do some cclever stuff in database
        }
    }

  return !addNewChat ? (
    &amp;lt;div className="sidebarChat"&amp;gt;
        &amp;lt;Avatar src=
{`https://api.dicebear.com/7.x/adventurer/svg?seed=${seed}`}/&amp;gt;
        &amp;lt;div className="sidebarChat_info"&amp;gt;
            &amp;lt;h2&amp;gt;{name}&amp;lt;/h2&amp;gt;
            &amp;lt;p&amp;gt;Last message...&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  ): (
    &amp;lt;div onClick={createChat}
    className="sidebarChat"&amp;gt;
        &amp;lt;h2&amp;gt;Add new Chat&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default SidebarChat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add a new room, add this to sidebarChat.js,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        if(roomName) {
            //do some cclever stuff in database
            db.collection("rooms").add({
                name: roomName,
            })
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Implement the react router&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s now implement the react router, such that when you click on any of the rooms, it reflects on the sidebarChat.js&lt;/p&gt;

&lt;p&gt;Install react-router-dom with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i react-router-dom&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Surround everything in App.js with a Router and Routes.&lt;/p&gt;

&lt;p&gt;Edit your App.js to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import './App.css';
import Chat from './Chat';
import Sidebar from './Sidebar';
import { BrowserRouter as Router, Routes, Route } from 
'react-router-dom';

function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;div className="app_body"&amp;gt;
        &amp;lt;Router&amp;gt;
          &amp;lt;Routes&amp;gt;
            &amp;lt;Route path="/rooms/:roomId" element={
              &amp;lt;&amp;gt;
                &amp;lt;Sidebar /&amp;gt;
                &amp;lt;Chat /&amp;gt;
              &amp;lt;/&amp;gt;
            } /&amp;gt;
            &amp;lt;Route path="/app" element={
              &amp;lt;&amp;gt;
                 &amp;lt;Sidebar /&amp;gt;
              &amp;lt;/&amp;gt;
            } /&amp;gt;
          &amp;lt;/Routes&amp;gt;
        &amp;lt;/Router&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Chat.js, let’s capture the roomId with useParams() hook:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const { roomId } = useParams();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The params in this case is the id variable passed to the link here: (The roomId) variable,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Route path="/rooms/:roomId" element={&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;as this is the path under which Chat.js is displayed.&lt;/p&gt;

&lt;p&gt;Add these imports to Chat.js,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import db from './firebase'
import { doc, onSnapshot } from 'firebase/firestore';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make use of the roomId and a useEffect hook to get to capture the roomName:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const [roomName, setRoomName] = useState("");

    useEffect(() =&amp;gt; {
        if (roomId) {
            const roomRef = doc(db, 'rooms', roomId); 
            const unsubscribe = onSnapshot(roomRef, (snapshot) =&amp;gt; {
                setRoomName(snapshot.data()?.name || ''); 
            });

            return () =&amp;gt; unsubscribe(); 
        }
    }, [roomId]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above, each time the roomId changes, useEffect ensures the roomName is updated.&lt;/p&gt;

&lt;p&gt;We also update the seed each time room Id changes:&lt;/p&gt;

&lt;p&gt;Add setSeed below setRoomName in Chat.js,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setRoomName(snapshot.data()?.name || ''); 
setSeed(Math.floor(Math.random() * 5000))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make the avatars consistent, we can rather set seed to the roomId value.&lt;/p&gt;

&lt;p&gt;In SidebarChat.js, replace Avatar source to this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Avatar src={&lt;/code&gt;&lt;a href="https://api.dicebear.com/7.x/adventurer/svg?seed=$%7Bid%7D"&gt;&lt;code&gt;https://api.dicebear.com/7.x/adventurer/svg?seed=${id}&lt;/code&gt;&lt;/a&gt;&lt;code&gt;} /&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In Chat.js, replace Avatar source to this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Avatar src={&lt;/code&gt;&lt;a href="https://api.dicebear.com/7.x/adventurer/svg?seed=$%7BroomId%7D"&gt;&lt;code&gt;https://api.dicebear.com/7.x/adventurer/svg?seed=${roomId}&lt;/code&gt;&lt;/a&gt;&lt;code&gt;} /&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Login with google authentication&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before working on the messages,&lt;/p&gt;

&lt;p&gt;Let us work on the Login stuff with google authentication:&lt;/p&gt;

&lt;p&gt;In App.js, we will render the app only if there is a user logged in.&lt;/p&gt;

&lt;p&gt;Add this to App.js:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [user, setUser] = useState(null);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In your src folder, add a Login.js component.&lt;/p&gt;

&lt;p&gt;Add these to firebase.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { getAuth, GoogleAuthProvider, signInWithPopup } 
from 'firebase/auth';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Login.js appears like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { Button } from '@material-ui/core';
import './Login.css';
import { auth, provider } from './firebase'; 
import { signInWithPopup } from './firebase';

const Login = () =&amp;gt; {
  const signIn = async () =&amp;gt; {
    try {
      // Destructure signInWithPopup from auth
      const { user } = await signInWithPopup(auth, provider);
      console.log('User signed in:', user);
    } catch (error) {
      alert(error.message);
    }
  };

  return (
    &amp;lt;div className="login"&amp;gt;
      &amp;lt;div className="login_container"&amp;gt;
        &amp;lt;img 
        src="https://tochat.be/whatsapp-icon-white.png" alt="" /&amp;gt;
        &amp;lt;div className="login_text"&amp;gt;
          &amp;lt;h1&amp;gt;Sign in to WhatsApp&amp;lt;/h1&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;Button type="submit" onClick={signIn}&amp;gt;
          Sign In With Google
        &amp;lt;/Button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Login;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your Login.css appears like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.login {
    background-color: #f8f8f8;
    height: 100vh;
    width: 100vw;
    display: grid;
    place-items: center;
}

.login_container {
    padding: 100px;
    text-align: center;
    background-color: white;
    border-radius: 10px;
    box-shadow: -1px 4px 20px -6px rgba(0, 0, 0, 0.2);
}

.login_container &amp;gt; img {
    object-fit: contain;
    height: 100px;
    margin-bottom: 40px;
}

.login_container &amp;gt; button {
    margin-top: 50px;
    text-transform: inherit !important;
    background-color: #0a8d48 !important;
    color: white;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to firebase on your browser and click on Authentication:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bCimJ-bK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706622198883/3f62062d-a003-4b5e-85fc-bd992525dbd6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bCimJ-bK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706622198883/3f62062d-a003-4b5e-85fc-bd992525dbd6.png" alt="" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Get started and this screen will pop up:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bLs-pAHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706622245969/37d02d19-c27d-4e19-a24b-8a34553ca1ae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bLs-pAHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706622245969/37d02d19-c27d-4e19-a24b-8a34553ca1ae.png" alt="" width="490" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on ‘Google’, the ‘enable’, then select a support email address, and click on ‘save’.&lt;/p&gt;

&lt;p&gt;We now need to wrap the app in state provider.&lt;/p&gt;

&lt;p&gt;In index.js, wrap the app in a state provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root.render(
  &amp;lt;React.StrictMode&amp;gt;
    &amp;lt;StateProvider initialState={initialState} reduce={reducer}&amp;gt;
      &amp;lt;App /&amp;gt;
    &amp;lt;/StateProvider&amp;gt;
  &amp;lt;/React.StrictMode&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Stateprovider acts as a data layer, where we can push and pull data. When we sign in, we push the user into the data layer, and we can pull the user from the data layer as well.&lt;/p&gt;

&lt;p&gt;In your scr folder, create a new file, StateProvider.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { createContext, useContext, useReducer } 
from "react";
import reducer, { initialState } from "./reducer"; 

export const StateContext = createContext();

export const StateProvider = ({ children }) =&amp;gt; (
  &amp;lt;StateContext.Provider value={useReducer(reducer, initialState)}&amp;gt;
    {children}
  &amp;lt;/StateContext.Provider&amp;gt;
);

export const useStateValue = () =&amp;gt; useContext(StateContext);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the src folder, create a new file, reducer.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const initialState = {
    user: null, //We start with the user ot being logged in
};

export const actionTypes = {
    SET_USER: "SET_USER", 
//We push signed in user to the data layer
};

const reducer = (state, action) =&amp;gt; {
    console.log(action);
    switch (action.type) {
        case actionTypes.SET_USER: 
            return {
                user: action.user,
            };

            default:
                return state;
    }
};

export default reducer;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in App.js, add this code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useStateValue } from './StateProvider';

const [{ user }, dispatch] = useStateValue();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Login.js now appears as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { Button } from '@material-ui/core';
import './Login.css';
import { auth, provider } from './firebase'; 
import { signInWithPopup } from './firebase';
import { useStateValue } from './StateProvider';
import { actionTypes } from './reducer';

const Login = () =&amp;gt; {
    const [{}, dispatch] = useStateValue();

    const signIn = () =&amp;gt; {
        signInWithPopup(auth, provider)
          .then((result) =&amp;gt; {
            console.log('user',result.user)
            dispatch({
              type: actionTypes.SET_USER,
              user: result.user,
            });
          })
          .catch((error) =&amp;gt; {
            alert(error.message);
          });
      };

  return (
    &amp;lt;div className="login"&amp;gt;
      &amp;lt;div className="login_container"&amp;gt;
        &amp;lt;img 
        src="https://tochat.be/whatsapp-icon-white.png" alt="" /&amp;gt;
        &amp;lt;div className="login_text"&amp;gt;
          &amp;lt;h1&amp;gt;Sign in to WhatsApp&amp;lt;/h1&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;Button type="submit" onClick={signIn}&amp;gt;
          Sign In With Google
        &amp;lt;/Button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Login;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the picture at the top on the image below,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qC-gzBfA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706626207835/4eb0309a-3a46-4fc6-9f53-80bc0b8e4a43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qC-gzBfA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706626207835/4eb0309a-3a46-4fc6-9f53-80bc0b8e4a43.png" alt="" width="475" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We made it pick the Google photoURL of the logged in user by editing the avatar source in sidebar.js to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Avatar src={user?.photoURL}/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and adding this line at the top in sidebar.js&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [{ user }, dispatch] = useStateValue();&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Adding a new collection, messages&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Inside the rooms collection, let’s have a new collection: messages&lt;/p&gt;

&lt;p&gt;Click on the first room, click on add collection.&lt;/p&gt;

&lt;p&gt;On collection id, type ‘messages’&lt;/p&gt;

&lt;p&gt;Click on auto id, on the Field input, type ‘message’ and under value, type ‘Hey guys’, then save&lt;/p&gt;

&lt;p&gt;Add another Field, ‘name’ and value ‘Asha’&lt;/p&gt;

&lt;p&gt;Add another field ‘timestamp’, Type ‘timestamp’ and choose a date and save.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Pulling messages from db&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now to pull the messages:&lt;/p&gt;

&lt;p&gt;We will create a state that keeps track of all the messages.&lt;/p&gt;

&lt;p&gt;Edit the useEffect hook in chat.js to add this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
        if (roomId) {
            const roomRef = doc(db, 'rooms', roomId);
            const unsubscribeRoom = onSnapshot(roomRef, 
            (snapshot) =&amp;gt; {
                setRoomName(snapshot.data()?.name || '');
            });

            const messagesQuery = query(
                collection(db, 'rooms', roomId, 'messages'),
                orderBy('timestamp', 'asc')
            );

            const unsubscribeMessages = onSnapshot(messagesQuery, 
            (snapshot) =&amp;gt; {
                setMessages(snapshot.docs.map((doc) =&amp;gt; doc.data()));
            });

            return () =&amp;gt; {
                unsubscribeRoom();
                unsubscribeMessages();
            };
        }
    }, [roomId]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And also add this line of code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [messages, setMessages] = useState([]);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, edit the div with className chatBody, to appear like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className="chat_body"&amp;gt;
                {messages.map(message =&amp;gt; (
                    &amp;lt;p className={`chat_message ${true 
                        &amp;amp;&amp;amp; "chat_reciever"}`}&amp;gt;
                        {message.timestamp ? (
                            &amp;lt;&amp;gt;
                                &amp;lt;span 
                className="chat_name"&amp;gt;{message.name}&amp;lt;/span&amp;gt;
                                {message.message}
                                &amp;lt;span className="chat_timestamp"&amp;gt;
                 {new Date(message.timestamp.toDate()).toUTCString()}
                                &amp;lt;/span&amp;gt;
                            &amp;lt;/&amp;gt;
                        ) : (

                            &amp;lt;span className="loading_timestamp"&amp;gt;
                                Loading ...
                            &amp;lt;/span&amp;gt;
                        )}
                    &amp;lt;/p&amp;gt;

                ))}
            &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a useEffect to scroll to the bottom of the chat in chat.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    useEffect(() =&amp;gt; {
        const chatBody = document.querySelector('.chat_body');
        chatBody.scrollTop = chatBody.scrollHeight;
    }, [messages]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Adding a message to messages collection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, lets add a message to the messages collection:&lt;/p&gt;

&lt;p&gt;In chat.js, we will have this in the sendMessage function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sendMessage = async (e) =&amp;gt; {
        e.preventDefault();
        console.log('You typed &amp;gt;&amp;gt;&amp;gt;', input);

        try {
            const messageRef = await addDoc(
                collection(db, 'rooms', roomId, 'messages'),
                {
                    message: input,
                    name: user.displayName,
                    timestamp: serverTimestamp(),
 // Use serverTimestamp instead of FieldValue.serverTimestamp()
                }
            );

            console.log('Message added with ID: ', messageRef.id);
        } catch (error) {
            console.error('Error adding message: ', error);
        }

        setInput("");
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Differentiate sender and receiver messages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we ensure that the chats from the sender are colored white, while those from the current signed in user are colored green.&lt;/p&gt;

&lt;p&gt;In chat.js in the div with the chat_body class, edit the p tag to look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;p className={`chat_message ${message.name === user.displayName 
&amp;amp;&amp;amp; "chat_reciever"}`}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will result to this effect:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_kKes3re--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706623078294/a48de63f-d1e0-47c8-9baa-d8c3810294d5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_kKes3re--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706623078294/a48de63f-d1e0-47c8-9baa-d8c3810294d5.png" alt="" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enable last seen in for each room&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To determine the last seen in chat.js, we add this code to get the timestamp of the last message in that room:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         &amp;lt;p&amp;gt;
            {messages.length &amp;gt; 0 &amp;amp;&amp;amp; "Last seen"}
               {
     messages.length &amp;gt; 0 &amp;amp;&amp;amp; messages[messages.length - 1]?.timestamp
                                ? (
     &amp;lt;span className="chat_timestamp" style={{ fontSize: '14px' }}&amp;gt;
     {new Date(messages[messages.length - 1]
.timestamp.toDate()).toUTCString()}
                                    &amp;lt;/span&amp;gt;
                                )
                                : 'No messages'
                        }

                    &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above, added just below the RoomName, displays a last seen timestamp when there are messages in the room, and displays ‘no messages’ when there are no messages in the room:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--34tUsykA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706623380531/6f43f961-2165-4c16-ad03-639d4694c93c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--34tUsykA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1706623380531/6f43f961-2165-4c16-ad03-639d4694c93c.png" alt="" width="800" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Determine last message for each room&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To determine the last message in SidebarChat.js,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [messages, setMessages] = useState("")

    useEffect(() =&amp;gt; {
        if(id){
            const messagesQuery = query(
                collection(db, 'rooms', id, 'messages'),
                orderBy('timestamp', 'desc')
            );

            const unsubscribeMessages = 
            onSnapshot(messagesQuery, (snapshot) =&amp;gt; {
                setMessages(snapshot.docs.map((doc) =&amp;gt; doc.data()));
            });

            return () =&amp;gt; {
                unsubscribeMessages();
            };
        }
    }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the p tag containing last message with this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;
                        {messages.length &amp;gt; 0 &amp;amp;&amp;amp; "Last message ..."}
                        {
                            messages.length &amp;gt; 0 
                                ? (
          &amp;lt;span className="chat_timestamp" 
                style={{ fontSize: '14px' }}&amp;gt;
                                        {messages[0]?.message}
                                    &amp;lt;/span&amp;gt;
                                )
                                : 'No messages'
                        }
                    &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploying app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let us go ahead to deploy our App&lt;/p&gt;

&lt;p&gt;On your terminal in the root folder:&lt;/p&gt;

&lt;p&gt;Run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;firebase login&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and proceed with the steps to login.&lt;/p&gt;

&lt;p&gt;Run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;firebase init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;on the pop up that comes up, scroll down and hit the spacebar on hosting, click enter, and click on ‘use an existing project’, select your whatsapp clone project and click Enter.&lt;/p&gt;

&lt;p&gt;On &lt;em&gt;‘What do you want to use as your public directory?’&lt;/em&gt;, type ‘build’ and press Enter.&lt;/p&gt;

&lt;p&gt;On &lt;em&gt;‘Configure as a single-page app&lt;/em&gt;’ type ‘y’&lt;/p&gt;

&lt;p&gt;On ‘&lt;em&gt;Set up automatic builds and deploys with GitHub?&lt;/em&gt;’ type ‘No’&lt;/p&gt;

&lt;p&gt;Run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;firebase deploy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will produce a link to your App:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://whats-app-clone-aac80.web.app/"&gt;https://whats-app-clone-aac80.web.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks so much for reading through! To support my blog you can make a donation through &lt;a href="https://www.buymeacoffee.com/angela300"&gt;https://www.buymeacoffee.com/angela300&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A simple Node Auth backend</title>
      <dc:creator>angela300</dc:creator>
      <pubDate>Wed, 24 Jan 2024 10:43:42 +0000</pubDate>
      <link>https://dev.to/angela300/a-simple-node-auth-backend-5860</link>
      <guid>https://dev.to/angela300/a-simple-node-auth-backend-5860</guid>
      <description>&lt;p&gt;&lt;strong&gt;This will include:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User Login and Signup&lt;br&gt;
Request Authorization (JWT)&lt;br&gt;
One-Time Pin System (OTP)&lt;br&gt;
Email Verification (OTP)&lt;br&gt;
Password Reset (OTP)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;App and Database Set up:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create the project directory in Vscode 'mkdir nodejs-auth'&lt;/p&gt;

&lt;p&gt;Initialize nodeJS project 'npm init -y'&lt;/p&gt;

&lt;p&gt;Install Express and other packages that we will need: 'npm install express dotenv mongoose jsonwebtoken bcrypt nodemailer cors nodemon'&lt;/p&gt;

&lt;p&gt;initialize our project into our new git repository: 'git init'&lt;/p&gt;

&lt;p&gt;In the project's root directory, create a new directory, 'src' folder, that will contain the code files. Create a '.env' file in the root directory, this file will contain all our secret keys and values. Also add a '.gitignore' file to check that, here, we specify that all files ending in .env should not be tracked, as well as the nodemodules folder Add this code to the .gitignore file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*.env
node_modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the Database setup: We use the cloud based Mongo DB. Login to the dashboard on Cloud.mongodb.com, Create a new project and database on the free tier. Allow your database to be accessible to all IP addresses. Create a new connection, choose driver NodeJS, copy the connection string that comes up and paste it into your .env file&lt;/p&gt;

&lt;p&gt;connection string: "MONGODB_URI = mongodb+srv://angela456:@cluster0.19fkfhm.mongodb.net/?retryWrites=true&amp;amp;w=majority"&lt;/p&gt;

&lt;p&gt;Replace the password area, with actual password for your database user. Make sure to also install MongoDB with ‘npm install mongodb’ command In the src directory create another directory, ‘config’ for configurations. In this new directory, create a new file, ‘db.js’ for database configurations. In the db.js file, require the dotenv file and configure it: Add this code to the db.js file,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require ("dotenv").config();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will enable us access the connection string in the ‘dotenv’ file Add a ‘Mongoose’ package in the db.js file as it will help us interact with the database. Add all this code to your db.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require ("dotenv").config();
const mongoose = require("mongoose")
//URI
const { MONGODB_URI } = process.env

const connectToDB = async () =&amp;gt; {
    try{
        await mongoose.connect(MONGODB_URI, {
            useNewUrlParser: true,
            useUnifiedTopology: true,
        });
    } catch(error){
        console.log(error)
    }
};

connectToDB();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Server setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we create an app.js file for creating the server. Add this code to app.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//MongoDb
require("./config/db")

const express = require("express")

//BodyParser will enable us supply json values to our server requests
const bodyParser = express.json;

//Cors will enable us make requests to the api from external applications
const cors = require ("cors")

//create server app
const app = express();

//app and cors passed as middleware
app.use(cors())
app.use(bodyParser());

module.exports = app;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Export the app to the index.js file Define a PORT in the dotenv file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MONGODB_URI = mongodb+srv://angela456:YIdqH3nQYqDdvstH@cluster0.19fkfhm.mongodb.net/?retryWrites=true&amp;amp;w=majority
PORT = 5000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your index.js file wil appear like this:&lt;br&gt;
const app = require ("./app")&lt;br&gt;
const { PORT } = process.env;&lt;/p&gt;

&lt;p&gt;const startApp = () =&amp;gt; {&lt;br&gt;
    app.listen(PORT, ()=&amp;gt; {&lt;br&gt;
        console.log(&lt;code&gt;Auth Backend is running on port ${PORT}&lt;/code&gt;)&lt;br&gt;
    });&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;startApp();&lt;br&gt;
In the package.json, add a script to run the app: The script will use the nodemon package which enables the app to continuously run and refresh in the background. The script also contains the locations of our index.js file and will appear like this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```  "scripts": {&lt;br&gt;
    "dev": "nodemon src/index.js"&lt;br&gt;
  }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Test the connection with: 'npm run dev' command in your projct root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
  </channel>
</rss>
