This commit is contained in:
Richard Crawley 2022-02-07 21:27:09 +00:00 committed by GitHub
commit 232bff7bf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,12 +2,17 @@ import React, { useEffect, useState } from "react";
import logo from "./logo.svg"; import logo from "./logo.svg";
import "./App.css"; import "./App.css";
function formatUsers(users) {
return `Users: ${users.map(user => user.login).join(", ")}`
}
function App() { function App() {
const [message, setMessage] = useState(); const [message, setMessage] = useState();
useEffect(() => { useEffect(() => {
fetch("/api/users") fetch("/api/users")
.then((res) => res.json()) .then((res) => res.json())
.then((res) => setMessage(res.message)) .then(formatUsers)
.then(setMessage)
.catch(console.error); .catch(console.error);
}, [setMessage]); }, [setMessage]);
return ( return (