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}
}
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