-
-
Notifications
You must be signed in to change notification settings - Fork 925
Change asynchronous get to fetch suggestion. #83
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
base: main
Are you sure you want to change the base?
Conversation
| You can use `get` when performing asynchronous operations as well: | ||
| ### `fetch` | ||
|
|
||
| You can use `fetch` when performing asynchronous operations as well: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that "as well" is appropriate here since it isn't connected with get anymore.
|
Why did you request my review since my previous comment is still open and unaddressed? |
Appears actually to be an error with GitHub mobile. I had requested a review on a private repository. I'll address your requested changes asap! I apologize for the inconvenience. |
|
I thing
const getUser = () => {
return fetch('/user').then(res => res.json());
};
const user = await getUser();
console.log(user);
let user;
const fetchUser = async () => {
const res = await fetch('/user').then(res => res.json());
user = res;
};
await fetchUser();
console.log(user); |
|
@letstri , I'm not sure I follow your distinction between |
|
@cjbarth Yes, exactly. It's more logical to me. It's like 'refetch' in TanStack Query. You won't get the value after the call "refetch". |
In the example displayed currently in the notes, it suggests that the asynchronous function would return instantaneously when it could return errors or throw. In my opinion, it would be better to recommend a namespace in which would reflect that accordingly.
The current example:
The proposed change:
The ideaology behind my suggestion is as follows. When you're playing fetch with a dog, the dog does not always immediately return. The dog may get distracted or while returning drop it before returning to the handler, thus erroring out and dropping the return.