Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!