0
export const get_post_api = id => {
  axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`)
}

enter image description here

export const get_post_api = id =>
  axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`)

enter image description here

The two codes have different response values. {} What's the difference between this?

villan
  • 11

1 Answers1

1

The second function returns Axios Promise but the first one does not return anything, even though it does make a request. If you change the first one to:

export const get_post_api = id => {
  return axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`)
}

It will be equivalent to:

export const get_post_api = id =>
  axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`)

In the second case, return is implied.

Source: Arrow function expressions

Irfanullah Jan
  • 3,336
  • 4
  • 24
  • 34