DEV Community

Discussion on: Do you use Axios or Fetch?

Collapse
 
tbhaxor profile image
Gurkirat Singh

You can use destructuring of the response object

// response from api
// { success: true, data : [1,2,3,4,5,6,7] }

axios({...})
  .then(({ body, ...res }) => {
     if ( body.success ) {
       console.log(body.data)  // [1,2,3,4,5,6,7]
     }
  })
Enter fullscreen mode Exit fullscreen mode