react-async-hook icon indicating copy to clipboard operation
react-async-hook copied to clipboard

Some extra info for onSuccess callback

Open unframework opened this issue 6 years ago • 1 comments

Hi Sebastien, thanks for adding onSuccess hooks! Just noting a couple things that could improve the usage flexibility.

  • often there is a need to know not just the result but also the original params that went into the execute method call (there is a workaround possible, but still could be nice to have this)
  • most of the time we need to ignore onSuccess if the operation/screen is no longer relevant, to not show unexpected toast message/do setState/etc; the former check can be accomodated via the isCurrent call (although I am not sure why it needs a call rather than being just a boolean), but the latter needs an is-mounted check, which would be great to pass in as a flag to onSuccess as well

Thanks for your work on this library, cheers!

unframework avatar Sep 09 '19 17:09 unframework

Hi, Great you like the lib :)

  1. there is a result.currentParams returned. If you really need the params of the success/error calls, I'm ok to include this

  2. I need it to be a call because you might want to show an error message and dismiss it 2secs later. isCurrent may help you avoid dismissing the wrong error message. I'd be ok to include isMounted into the callback if it helps

I don't have time this week to work on this but if you want feel free to open a PR :)

slorber avatar Sep 09 '19 18:09 slorber