Fix formatting of API response

Signed-off-by: Richard Crawley <richard.crawley@protonmail.com>
This commit is contained in:
Richard Crawley 2022-02-07 21:22:51 +00:00
parent 6531426a96
commit a3a2d02aed

View File

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