Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
React not changing UseState when socket io is receiving message it only works when I refresh page

I have created social media app with chat when I send message from one user to another chat never updates with new message until I refresh bot users and texting becomes normal and works fine but when I try to text without refreshing it won't work. Even when text does not change sometimes I get console log with message that I sent from one user to another. Console log (data) is working most of the time but setArrivalMessage is never triggered for some reason until I refresh bot pages.

This is picture of console.log that I am getting (sometimes I even do not get console log) enter image description here

useEffect(() => { 
    socket.current.on("getMessage", (data) => {
        setArrivalMessage({ 
           
           
            sender: data.senderId,
            text: data.text,
            createdAt: Date.now(),
        })
    })
},[])

useEffect(() => {
    
    arrivalMessage &&
      currentChat?.members.includes(arrivalMessage.sender) &&
      setMessages((prev) => [...prev, arrivalMessage]);
  }, [arrivalMessage, currentChat]);
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda