Created
June 26, 2020 15:53
-
-
Save argodeep/dc6201caf9c89c0d277a8d56b2209909 to your computer and use it in GitHub Desktop.
React Axios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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