Last active
June 2, 2021 18:22
-
-
Save harshaktg/9305f90352437e177ffaf94dd3dfd412 to your computer and use it in GitHub Desktop.
useAxios - Step 1
This file contains 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 { useEffect } from 'react'; | |
import axios from 'axios'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
const App = () => { | |
const fetchData = async () => { | |
try { | |
const res = await axios.get('/posts'); | |
console.log(res.data); | |
} catch (err) { | |
console.log(err); | |
} | |
}; | |
useEffect(() => { | |
fetchData(); | |
}, []); | |
return <div className="app"></div>; | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment