fix: allow returning of falsy values from useAsync #670
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #493
If a falsy value is returned from useAsync, the client will always run the request again.
You could completely allow falsy values by adding a
hasRun
ssrRef but I fear it would pollute the global space.So, as a compromise, with this change you can avoid having the client re-run a request if you return any falsy value other than null (and void)
Edit:
I guess another solution would be to convert the default ref value to an object, something like
{ data: null, hasRun: false }
and maintain the single ssrRef that's already generated currently. But I think the proposed change is simple enough and really has no downsides to current behavior afaik.