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

107
Visualizações
My socket.IO data is loading locally but not on Heroku

I am working on a 2 screen chat application which displays a list of connected users on the first screen and when a user is clicked, the user's data is stored in the redux state and it is retrieved in the second screen to load the message of the user on the second screen.

On my local machine, It loads the user's data on the second screen, but when I deployed to heroku, It doesn't load the user's data. i don't know if it happens so fast and should be delayed for some milliseconds

SCREEN ONE

const showChat = (id) => {
    dispatch({
      type: 'SET_CHAT_USER',
      payload: id,
    })
  }


return (

<div style={{ overflowY: 'scroll', height: 500 }}>
    {chats.length > 0
        ? chats.map((chat, i) => (
            <Typography variant='subtitle2' onClick={() => showChat(chat.messengerId)}>
                {chat.firstName} {chat.lastName}
            </Typography>    
            ))
            : 'No Chat'}
</div>
)

SCREEN TWO

import * as io from 'socket.io-client'

const MessageChat = () => {
   const { chatUser } = useSelector((state) => ({ ...state })) // retrieved the id

   const socket = useRef()

    useEffect(() => {
    const loadMessages = () => {
      socket.current.emit('loadMessages', {
        userId: user._id,
        messagesWith: chatUser,
      })

      socket.current.on('messagesLoaded', ({ chat }) => {
        setMessages(chat.messages)
        setBannerData({
          firstName: chat.messagesWith.firstName,
          lastName: chat.messagesWith.lastName,
          profilePicUrl: chat.messagesWith.profilePicUrl,
        })

        openChatId.current = chat.messagesWith._id
        divRef.current && scrollDivToBottom(divRef)
      })

      socket.current.on('noChatFound', async () => {
        const { firstName, lastName, profilePicUrl } = await ChatGetUserInfo(
          chatUser,
          user.token
        )

        setBannerData({ firstName, lastName, profilePicUrl })
        setMessages([])

        openChatId.current = chatUser
      })
    }

    if (socket.current && chatUser) {
      loadMessages()
    }
  }, [chatUser])
}
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