fetch-event-source
fetch-event-source copied to clipboard
Variable outside await fetchEventSource is undefined
trafficstars
The code is working as expected
onmessage(ev) {
console.log(ev.data);
}
However, when using the ev.data , i can't access variable outside fetchEventSource. How to handle it ?
The problem right there @ducknificient is that the closure doesn't know about the variables outside fetchEventSource methods. I handled that issue by using var variables declared somewhere else outside fetchEventSource call. Those variables will be available on the global scope and then you'll be able to use them inside those events. Binding the method call didn't work for me.