Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useAsyncCallback doesn't require a dependency array? #82

Open
theogravity opened this issue Feb 15, 2022 · 1 comment
Open

useAsyncCallback doesn't require a dependency array? #82

theogravity opened this issue Feb 15, 2022 · 1 comment

Comments

@theogravity
Copy link

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?

@JoshWellPharma
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants