import fetch from "isomorphic-unfetch"
const fetchPerson = async ({ id }) => {
const response = await fetch(`https://swapi.co/api/people/${id}/`)
if (!response.ok) throw new Error(response.status)
const Person = ({ id, person }) => (
<Async promiseFn={fetchPerson} initialValue={person} id={id}>
<Async.Pending>Loading...</Async.Pending>
<Async.Rejected>{error => <ErrorMessage {...error} />}</Async.Rejected>
<Async.Fulfilled>{data => <Greeting {...data} />}</Async.Fulfilled>
Person.getInitialProps = async ({ req }) => {
const person = await fetchPerson({ id })