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

[FEATURE] Add isSuccess, isLoading etc to useAction return object #61

Closed
2 tasks done
John-Dennehy opened this issue Feb 7, 2024 · 5 comments
Closed
2 tasks done
Labels
enhancement New feature or request

Comments

@John-Dennehy
Copy link

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

@John-Dennehy John-Dennehy added the enhancement New feature or request label Feb 7, 2024
@John-Dennehy
Copy link
Author

FYI - I'd be happy to raise a PR if there is an appetite for this.

@TheEdoRan
Copy link
Owner

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.

@John-Dennehy
Copy link
Author

Sorry for missing that. That is a shame really.

@TheEdoRan
Copy link
Owner

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?

TheEdoRan added a commit that referenced this issue Feb 8, 2024
Sometimes it's useful and more elegant to check the action status using a function instead of string
equality. This commit exports util functions to do that, while ensuring the same discriminated
behavior that the single `status` property provides to the user, thanks to TypeScript's type
predicates feature.

re #61, re #37
@TheEdoRan
Copy link
Owner

Action status utility functions implemented in 6.1.0 release. Relevant documentation can be found here.

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

No branches or pull requests

2 participants