Created
July 6, 2020 15:10
-
-
Save coryhouse/68ddab277fa896c54dd550c2f9bacedc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from "react"; | |
import { getUsers } from "./services/userService"; | |
export default function CentralDemo() { | |
const [users, setUsers] = useState([]); | |
const [loading, setLoading] = useState(true); | |
const [error, setError] = useState(null); | |
useEffect(() => { | |
getUsers() | |
.then(json => { | |
setUsers(json); | |
setLoading(false); | |
}) | |
.catch(err => { | |
console.error(err); | |
setError(err); | |
}); | |
}, []); | |
if (loading) return "Loading..."; | |
if (error) return "Oops!"; | |
return users[0].username; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment