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

139
Views
ReactJs and Singleton issue with updating

Firstable, I know its not good practice to share data like this in react App, But - let say "I have no choice" Now I have an issue with singleton in ReactJs. I can see that if i trying to get instance of singleton - constructor works only once. Inside constructor I have subscription to web socket which updates data inside singleton. But then Im try to reach the data from different places in app - its not update - shows me version then I took instance. How can I solve it?

export default class Manager {
    constructor(){
        this.data = null;
        socket.on('event', this.parseData)
    }

    static getInstance(){
       if (!this.instance) {
         this.instance = new QuotasManager();
       }
      return this.instance;
    }
   
   parseData(data){ ///parsedata}
   
   getData(){ return this.data}

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sorry for disturb - I found that its my fault. I loose my scope then use callback on socket event. Just forgot to add arrow function to got my this

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!