title: How can I sset react state with response coming from socket.on as Promise?
body: <p>I'm working on a chat app using NestJs as backend and React as frontend with socket.io. I would like to send 'conversations' to frontend with socket.</p>
  <p>On the backend part :</p>
  <p>chat.service.ts:</p>
  <pre><code>getConversationsForCompany(companyId: number){
      const  conversations =  this.conversationsRepository.find({
        where: {company: companyId},
        order: {lastUpdated: &quot;ASC&quot;},
        relations: ['user','company','companyMessages','userMessages']
      });
      if(conversations) {
        
        return conversations;
      }
      throw new WsException('No convos for company')
    }
  </code></pre>
  <p>chat.gateway.ts:</p>
  <pre><code>    async handleConnection(socket: Socket) {
      const company = await this.conversationService.getCompanyFromSocket(socket);
      if (!company) {
        this.handleDisconnect(socket);
      }
      else  {
        socket.data.user = company;
        this.getConversationsForCompany(socket, company.id);
      }
   async getConversationsForCompany(socket: Socket, companyId: number) {
      //const conversations = await this.conversationService.getConversationsWithUsers(companyId);
        const conversations =  this.conversationService.getConversationsForCompany(companyId);
      this.server.to(socket.id).emit('conversationsForCompany', conversations)
    }
  </code></pre>
  <p>in react part:</p>
  <pre><code>import {socket} from './socket.js'
  .
  .
  .
  const [convos, setConvos] = useState([]);
  useEffect(() =&gt; {
  socket.on(url, data =&gt; {
  setConvos(data);
  }
   },[socket]);
  </code></pre>
  <p>Any help will be much appreciated !</p>