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 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 (
|
||||||
|
Loading…
Reference in New Issue
Block a user