Message from JavaScript discussions

September 2020

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

export const getAllUsers = () => {

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

}

Message permanent page

— 

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);
}
}

— 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

— getAllUsers
.then(data => setData(data))
.catch(error =>....)