Created
March 8, 2024 04:17
-
-
Save Lahirutech/e0c568c8d5d3062b86e7ce4625b8c71a to your computer and use it in GitHub Desktop.
fetch Using Axios
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 axios from 'axios' | |
import { useEffect } from 'react' | |
import './App.css' | |
// https://jsonplaceholder.typicode.com/posts | |
export default function App() { | |
const FetchAPI = async (url: string): Promise<any> => { | |
try { | |
const response = await axios.get(url) | |
console.log(response) | |
return response.data | |
} catch (error) { | |
console.log("error", error) | |
} | |
} | |
useEffect(() => { | |
FetchAPI("https://jsonplaceholder.typicode.com/posts2").then((data) => { | |
console.log(data) | |
}) | |
}, []) | |
return ( | |
<main> | |
React ⚛️ + Vite ⚡ + Replit 🌀 | |
</main> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment