[FEATURE] Add isSuccess, isLoading etc to useAction return object
John-Dennehy opened this issue · comments
Are you using the latest version of this library?
- I verified that the issue exists in the latest next-safe-action release
Is there an existing issue for this?
- I have searched the existing issues and found nothing that matches
Suggest an idea
While status
already exists, I find myself needing to creating the same additional "boiler-plate" code around the status string value every time I use useAction; specifically creating boolean variables such as isLoading
for button state.
While not a high priority, it would be nice if the response object was a more similar to projects like tanstack/react-query that include both the status
string and boolean variables like:
- isLoading
- isSuccess
- isError
I imagine any accepted change would need to be applied to useOptimisticAction too.
Additional context
No response
FYI - I'd be happy to raise a PR if there is an appetite for this.
Hi @John-Dennehy, next-safe-action v3 actually returned an object with hasExecuted
, isExecuting
, hasSucceeded
and hasErrored
properties, this changed in v4, you can read about it in the v3 to v4 migration guide on the website.
This specific change has been already discussed in this issue, and in this comment I explained why I made it and a possible solution to avoid repeating code, defining simple util functions for the scope.
Please let me know if there's anything else I can help you with, thank you.
Sorry for missing that. That is a shame really.
No worries! By the way, we could export those utility functions from the library itself, but I'm not sure if this is the right thing to do, not everybody will use them, and defining them in one place is quite simple already. What do you think?
Action status utility functions implemented in 6.1.0
release. Relevant documentation can be found here.