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

276
Views
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 answers
Answer question

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 Report
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!