From a3a2d02aed0dc9f489795b08048d5532ebeb2fec Mon Sep 17 00:00:00 2001 From: Richard Crawley Date: Mon, 7 Feb 2022 21:22:51 +0000 Subject: [PATCH] Fix formatting of API response Signed-off-by: Richard Crawley --- react-rust-postgres/frontend/src/App.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/react-rust-postgres/frontend/src/App.js b/react-rust-postgres/frontend/src/App.js index af8ad01..9c23c42 100644 --- a/react-rust-postgres/frontend/src/App.js +++ b/react-rust-postgres/frontend/src/App.js @@ -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 (