Skip to content

Instantly share code, notes, and snippets.

@harshaktg
Last active June 2, 2021 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshaktg/9305f90352437e177ffaf94dd3dfd412 to your computer and use it in GitHub Desktop.
Save harshaktg/9305f90352437e177ffaf94dd3dfd412 to your computer and use it in GitHub Desktop.
useAxios - Step 1
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