Fix formatting of API response
Signed-off-by: Richard Crawley <richard.crawley@protonmail.com>
This commit is contained in:
parent
6531426a96
commit
a3a2d02aed
7
react-rust-postgres/frontend/src/App.js
vendored
7
react-rust-postgres/frontend/src/App.js
vendored
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user