Async useEffect hook. Just because I was lazy to create this hook on every project.
$ npm install react-use-effect-async
import React from 'react';
import useEffectAsync from 'react-use-effect-async';
export function Demo() {
const [data, setData] = React.useState(null);
useEffectAsync(async () => {
const response = await fetch('https://api.github.com/users/abranhe');
const data = await response.json();
setData(data);
}, [data]);
return <div>{!data ? <p>Loading...</p> : <p>{data.name}</p>}</div>;
}