Was this helpful?
import React from "react"
import Async from "react-async"
const fetchPerson = async ({ id }, { signal }) => {
const response = await fetch(`https://swapi.co/api/people/${id}/`, { signal })
if (!response.ok) throw new Error(response.statusText)
return response.json()
}
const App = () => {
return (
<Async promiseFn={fetchPerson} id={1}>
<Async.Pending>Loading...</Async.Pending>
<Async.Rejected>{error => <ErrorMessage {...error} />}</Async.Rejected>
<Async.Fulfilled>{data => <Greeting {...data} />}</Async.Fulfilled>
</Async>
)
}