Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Created July 6, 2020 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryhouse/68ddab277fa896c54dd550c2f9bacedc to your computer and use it in GitHub Desktop.
Save coryhouse/68ddab277fa896c54dd550c2f9bacedc to your computer and use it in GitHub Desktop.
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