import React, { useContext, useEffect, useState } from 'react' import Contact from '../Contact'; import "./Contacts.css"; import { UserContext } from '../../contexts/UserProvider'; import { ChatContext } from '../../contexts/ChatProvider'; import { SocketContext } from '../../contexts/SocketProvider'; function Contacts({ }) { // const [activeContact, setActiveContact] = useState({}); const { contacts, setContacts, currentChat, setCurrentChat, lastMessages, } = useContext(ChatContext); const { user } = useContext(UserContext); const socket = useContext(SocketContext); // handleClick useEffect(() => { if (!socket) return; socket.on("contact", (contact) => { var newContacts = [...contacts, contact]; newContacts.sort((a,b)=>b.last_message.send_at - a.last_message.send_at); setContacts(newContacts); }); const cleanUp = () => { if (!socket) return; socket.off("contact"); } return cleanUp; }, [socket]) return (