event-iterator icon indicating copy to clipboard operation
event-iterator copied to clipboard

How can this be used with for instance react hooks?

Open EloB opened this issue 5 years ago • 1 comments

I really starting to like this library.

One thing that I don't understand it how to use this with for instance useEffect in React where you have an external teardown function...

Can you provide any example how to do that? <3

EloB avatar Nov 04 '20 09:11 EloB

useEffect(() => {
  (async () => {
    for (const event subscribe.call(instance, 'something')) {
      // Do something
    }
  })();
  return () => {
    // Teardown function
    // Is it possible to teardown that asyncIterator somehow?
  };
})

EloB avatar Nov 04 '20 09:11 EloB