Message from JavaScript discussions

September 2020

— I created a folder called services and then ...there I created files like user.js, roles.js...etc

— 

It is like .....services/users.js

export const getAllUsers = () => {

const res = api.get('/users');
return res.data;

}

— Then in the component it's like...

import {getAllusers} from '../services/.users.js';

componentDidMount(){
try{
const data = await getAllUsers();
setData(data);
}
catch(err){
window.alert(err.message);
}
}

Message permanent page

— But this try catch bull is over the place.

— Is it a good approach or do I need to do something else?

— How are you using await there?

— It returns a promise.

— It's an async function

— Promise would be cleaner here

— Wt do u mean by tht?

— Wait guys

— There is axios there is fetch