Change asynchronous get to fetch suggestion.#83
Change asynchronous get to fetch suggestion.#83haIIux wants to merge 2 commits intokettanaito:mainfrom
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.
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.