import { useState, useEffect} from 'react'
function useFetchData(url) {
const [data, setData] = useState(null);
useEffect(() => {
fetch(url)
.then((res) => res.json())
.then((data) => setData(data))
.catch((err) => console.log(`Error: ${err}`));
}, [url]);
return { data };
}
export default useFetchData
import useFetchData from './useFetchData'
function Users() {
const { data } = useFetchData("https://api.github.com/users");
return (
<div>
{data && (
data.map((user) =>(
<div className="text-white" key={user.id}>
<h1> {user.login} </h1>
<p> { user.type } </p>
</div>
))
)}
</div>
)
}
export default Users;