i have probably a small trouble. Here is a function that returns a Promise.
export default ()=>{
const socket = io(config.crypt_compare_api_url);
let subscription = config.subscription;
socket.emit('SubAdd', { subs: subscription });
return new Promise(resolve => {
socket.on("m",resolve);
});
}
And a here i use it. It's imported as get_crypto
get_crypto().then((parsedData)=>{
let el=this.state.currencies.find(element=> element.name===parsedData.name);
if(el)
{
el.price=parsedData.price;
}
else this.state.currencies.push(parsedData);
this.setState( {
currencies: this.state.currencies
});
});
** 'then' function always have to repeat after socket gets a message. But it works only one time,**