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

204
Views
Infinite loop request socket in reactjs?

I'm building real-time comment feature for my app . I'm using socket.io for my back-end (nodejs ) and socket.io client for frontend - reactjs . I don't understand why my app is send a infinite loop request .Can someone please help?

I use socket in my app.js and pass props socket to my route , but when i create socket in MyApp , I test on Edge and can not prevent client send request infinite loop .

import io from 'socket.io-client'
    const socket = io();


function App() {


  useEffect(()=>{
    socket.on('connect',(id)=>{
      console.log(id)
    })
  },[])
  
  return (
    <Provider store={store}>
<ToastContainer
position="top-right"
autoClose={3000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover={false}
/>
{/* Same as */}
    <div className="App">
      <Header/>
      <Switch>
      <Redirect exact path="/" from="/" to="/home" />

        <Route exact path='/home' component={HomePage} />
        <Route exact path='/shop' component={ShopPages}/>
        <Route exact path="/user/auth" component={AuthPage}/>
        <Route exact path='/product/:id' component={ProducDetail}/>
        {/* <PrivateRoute component={AuthPage} path="/user/auth" exact /> */}
        <PrivateRoute component={UserPage} path="/user/infor" exact />
        {/* <PrivateRoute path="/user/auth/verify/:activation_token" exact component={VerifyPage}/> */}

        <PrivateRoute component={VerifyPage} path="/user/auth/verify/:activation_token" exact />

        <Route component={Notfound} />
      </Switch>
      </div>
    </Provider>
  );
}

export default App;

My Server Nodejs

require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const cors = require('cors')
const fileUpload  = require('express-fileupload')
const cookieParse = require('cookie-parser')
const Comments = require('./models/commentModel')



const app = express()
app.use(cors())

app.use(express.json())
app.use(cookieParse())
app.use(fileUpload({
    useTempFiles:true
}))

// socket

const http = require('http').createServer(app)
const io = require('socket.io')(http)

let users = []
io.on('connection',socket=>{
    console.log(socket.id + 'connected')
 socket.on('disconnect',()=>{
        console.log(socket.id + 'disconnected')
    })
    
})

Request Loop

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!