DEV Community

Ola Abaza
Ola Abaza

Posted on

1 RN Thing a Day – Day 11: When Is await Unnecessary?

The Basic Rule
Inside an async function:

πŸ‘‰ If you are just returning a Promise, you do NOT need await.

Simple Example
Look at these two functions:

Version 1

async function getData() {
  return await fetchData()
}
Enter fullscreen mode Exit fullscreen mode

Version 2

async function getData() {
  return fetchData()
}
Enter fullscreen mode Exit fullscreen mode

Both functions do exactly the same thing.

  • They return a Promise
  • They resolve to the same value
  • No behavior difference

So in Version 1, the await is unnecessary.

Why This Works
An async function automatically wraps its return value in a Promise.

So when you write:

return fetchData()

Enter fullscreen mode Exit fullscreen mode

JavaScript already knows it’s a Promise and returns it correctly.

Adding await just waits for the Promise and then returns the same resultβ€”without any benefit.

When await IS Needed
You need await only when you actually want to use the result.

async function getUserName() {
  const user = await fetchUser()
  return user.name
}
Enter fullscreen mode Exit fullscreen mode

Here await is required because you need to access user.name.

Easy Rule to Remember

Use await when:

  • You need the resolved value
  • You want to do logic with the result
  • You have multiple async steps

Skip await when:

  • You are only returning a Promise
  • No extra logic is needed

TL;DR
Inside an async function:
πŸ‘‰ If you are only returning a Promise, don’t use await.

Top comments (0)