react-async-hook
react-async-hook copied to clipboard
useAsyncCallback doesn't require a dependency array?
I'm trying to use this in place of react's useCallback(), and was wondering if a dependency array is required as I don't see one in the signature. Based on the usage examples, I get a sense that this isn't meant to replace it?
No this is not like reacts useCallback. Instead you use useAsyncCallback when you want to control when the async operation happens. E.g. on a form submit.
you could do something like:
// where createUser is your async function that creates you a user
const createUserAsync = useAsyncCallback(createUser);
const onSubmit = (values) => createUserAsync.execute(values);
<form onSubmit={onSubmit}>
<input name="email" />
<input name="password" type="password" />
</form>