Skip to content

Instantly share code, notes, and snippets.

@argodeep
Created June 26, 2020 15:53
Show Gist options
  • Save argodeep/dc6201caf9c89c0d277a8d56b2209909 to your computer and use it in GitHub Desktop.
Save argodeep/dc6201caf9c89c0d277a8d56b2209909 to your computer and use it in GitHub Desktop.
React Axios
import axios from "axios";
const API = {
backend: "https://randomuser.me/api/",
};
export const fetchUsers = async () => {
let res = await axios.get(API.backend + '?inc=name,phone&results=20&nat=us');
try {
return res.data.results
}
catch(err) {
console.log("Error", err);
return []
}
finally {
console.log('Request Successfull');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment