- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 40
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
[FEATURE] Return async function from hooks #72
Comments
Hi @pharmarin, I don't think this is possible, since next-safe-action hooks use the Please let me know if this solves your issue, thanks. |
I really need to await and catch the call while getting current status in my component. So I "created" a hook that does the work |
Unfortunately this isn't currently supported, and it isn't a next-safe-action issue, so there's not much I can do to fix it. Please track this issue from React to get updates regarding this. At this time, though, React documentation states:
React recommends to use |
This will be perfect when it gets merged : facebook/react#28491 |
Yes @pharmarin! That hook will surely change the way we handle Server Actions in next-safe-action, and also pave the way for Form Actions support. |
I'm implementing stateful actions in the library right now, since the new hook is finally available in Next.js, and I just found out that dispatcher: () => void So apparently it's not going to solve this issue. Repo with a test: next-useactionstate-test. re #94 |
…cAction` hooks (#147) This PR adds the `executeAsync` function to the return object of `useAction` and `useOptimisticAction` hooks. It's currently not possible to add it to the `useStateAction` hook. As the name suggests, `executeAsync` returns a Promise with the same result of the `safeActionFn` you pass to the hook, and it allows to await the result of the action. re #137, #72, #94
Are you using the latest version of this library?
Is there an existing issue for this?
Suggest an idea
I would like to have an async function returned from hooks. This function would be executed from event handlers to set internal state with more granularity.
Additional context
No response
The text was updated successfully, but these errors were encountered: