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)

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]);