Skip to content

Change asynchronous get to fetch suggestion.#83

Open
haIIux wants to merge 2 commits into
kettanaito:mainfrom
haIIux:get-to-fetch-suggestion
Open

Change asynchronous get to fetch suggestion.#83
haIIux wants to merge 2 commits into
kettanaito:mainfrom
haIIux:get-to-fetch-suggestion

Conversation

@haIIux

@haIIux haIIux commented Dec 14, 2022

Copy link
Copy Markdown

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:

You can use get when performing asynchronous operations as well:

async function getUser(id) {
  const user = await fetch(`/api/user/${id}`)
  return user
}

The proposed change:

fetch

You can use fetch when performing asynchronous operations as well:

async function fetchUser(id) {
  const user = await fetch(`/api/user/${id}`)
  return user
}

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.

@haIIux haIIux changed the title Change asynchronous to fetch suggestion. Change asynchronous get to fetch suggestion. Dec 14, 2022
Comment thread README.md
You can use `get` when performing asynchronous operations as well:
### `fetch`

You can use `fetch` when performing asynchronous operations as well:

Copy link
Copy Markdown

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.

@haIIux haIIux requested a review from cjbarth November 14, 2023 15:43
@cjbarth

cjbarth commented Nov 15, 2023

Copy link
Copy Markdown

Why did you request my review since my previous comment is still open and unaddressed?

@haIIux

haIIux commented Nov 15, 2023

Copy link
Copy Markdown
Author

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.

@letstri

letstri commented Feb 16, 2024

Copy link
Copy Markdown

I thing fetch should be in another cases.

get for returning value

const getUser = () => {
  return fetch('/user').then(res => res.json());
};

const user = await getUser();

console.log(user);

fetch for fetching data to some variable

let user;

const fetchUser = async () => {
  const res = await fetch('/user').then(res => res.json());

  user = res;
};

await fetchUser();

console.log(user);

@cjbarth

cjbarth commented Jul 22, 2025

Copy link
Copy Markdown

@letstri , I'm not sure I follow your distinction between get and fetch here. Are you just saying that get directly returns a value and that fetch gets a value and then puts it "somewhere"?

@letstri

letstri commented Oct 29, 2025

Copy link
Copy Markdown

@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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants