pass onResolve/onReject callback with run
rajivhbk opened this issue · comments
Question.
I want to keep all my async methods in a context. So that i could share the states with different components. The issue i'm facing is passing a onResolve/onReject callback from the component to the useAsync hook defined in the a context.
You can chain on promise
instead. But be aware you have to pass a rejection handler.
This works but i was expecting a better solution. Like passing a onResolve and OnReject callback with the run method. That way i wont have to chain on promise.
Yes this was certainly considered but not technically possible, or at least has some big implications. One of the issues is dealing with such handlers getting attached to a promise which eventually gets replaced by another promise but those handlers never get garbage collected so you end up with a memory leak.