Async components
Creating an async component with useFetch
useFetchimport React from "react"
import { useFetch } from "react-async"
const Person = ({ id }) => {
const { data, error } = useFetch(`https://swapi.co/api/people/${id}/`, {
headers: { accept: "application/json" },
})
if (error) return error.message
if (data) return `Hi, my name is ${data.name}!`
return null
}
const App = () => {
return <Person id={1} />
}More flexibility with useAsync
useAsyncLast updated
Was this helpful?