DEV Community

Discussion on: Homebrew React Hooks: useAsyncEffect Or How to Handle Async Operations with useEffect

Collapse
 
harjis profile image
Joonas Harjukallio

Looks really nice!

Do you know if there is a way to extend this so that it could be executed on demand? What I'm after is a basic save functionality.

What I have been doing so far is just having a callback which calls an async function. The callback is then called from the save buttons onClick handler. This of course doesn't support cleaning up so if the component gets unmounted before saving request has finished it might call setState on an unmounted component

Collapse
 
n1ru4l profile image
Laurin Quast

I thought about creating useAsyncCallback. Shouldn‘t be to hard to implement!