Skip to content

Instantly share code, notes, and snippets.

@Lahirutech
Created March 8, 2024 04:17
Show Gist options
  • Save Lahirutech/e0c568c8d5d3062b86e7ce4625b8c71a to your computer and use it in GitHub Desktop.
Save Lahirutech/e0c568c8d5d3062b86e7ce4625b8c71a to your computer and use it in GitHub Desktop.
fetch Using Axios
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