Getting an Empty array from the firestore

  firebase, javascript, reactjs

This is my code for LeftBar Component
I want to get the data stored in the "contacts" document in the firebase but getting an empty array. Idk know why this is happening. And one thing if anyone can tell me how to do it with class-based component ( how to use that use effect thing into ComponentDidMount and ComponentDidUpdate) as I have two other class Components which are also using the same functionality Please help

import React, {useState , useEffect}  from "react";
import { Avatar, IconButton } from "@material-ui/core";
import AddCircleIcon from "@material-ui/icons/AddCircle";
import MoreIcon from "@material-ui/icons/More";
import ChatBubbleOutlineIcon from "@material-ui/icons/ChatBubbleOutline";
import SearchIcon from '@material-ui/icons/Search';
import LeftChats from './LeftChats';
import "./LeftBar.css";
import db from './firebase'

function LeftBar () {
  const [contacts, setContacts] = useState([])

  useEffect(() => {
    db.collection("contacts").onSnapshot((snapshot)=> setContacts(> ({
        id :,
        data :,

    return (
      <div className="leftbar">
        <div className="left-header">
          <Avatar />
          <div className="left-right-header">
            <AddCircleIcon />
            <MoreIcon />
            <ChatBubbleOutlineIcon />

        <div className="left-search">
            <div className='input-container'>
            <input type='text' placeholder='Search...'/>

        <div className="left-chats">
     contact =>( 
                <LeftChats key={} id = {} username= 

export default LeftBar;

This is my LeftChat Component

import React, { Component } from 'react'
import { Avatar} from "@material-ui/core";

class LeftChats extends Component {
   constructor(props) {
       this.state = {
            data : ''
        return  (
            <div className='leftchats'>
                <div className='chats-info'>
                <p>Some text message...</p>

export default LeftChats

Source: Ask Javascript Questions