Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
Why am i getting " Expected an assignment or function call and instead saw an expression" error here?

Im getting " Expected an assignment or function call and instead saw an expression" error at the seconduse effect, it finds the socket port correctly, am i performing the socket.on wrong? the socket server starts correctly, and i even get my console log in index.js to output "a user is connected"

  const [socket, setSocket] = useState(null)

  useEffect(() => {
    setSocket(io("ws://localhost:8900"))
  }, [])

  useEffect(() => {
    socket?.on("welcome", (message) => {
     
      console.log(message)
    })
  }, [socket])

index.js for socket

const io = require("socket.io") (8900, {
    cors: {
        origin: "http://localhost:3000",
    }
})
io.on("connection", (socket) =>{
    console.log("a user is connected")
   io.emit("welcome","hello this is socket server")
})

edit: whats even weirder, is the "hello this is a socket server" actually console logs, then this error still happens... not sure why...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Figured out my issue, set the socket with socket.current if your using a useEffect in react, if your just doing a const socket , then thats fine. Their will be socket Issues on any refresh or update, causing errors for something trying to call an old socket, using a different socketId.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda