import React, { useState, useEffect } from "react"; const Posts = (props) => { const [state, setState] = useState({ user: { username: "" }, posts: [ { id: 1, upvotes: 2, text: "Action for Climate Change", comments: 0, topics: ["climate change", "air pollution"], }, ], }); const requestOptions = { method: "GET", headers: { Authorization: `Bearer ${localStorage.getItem("token")}`, }, }; const callAPI = () => { fetch(`${process.env.REACT_APP_API_ENDPOINT}/posts/`, requestOptions) .then((response) => response.json()) .then((data) => { if (data !== undefined) { setState(data); } }); }; useEffect(() => { callAPI(); }, []); const maybePluralize = (count, noun, suffix = "s") => `${count} ${noun}${count !== 1 ? suffix : ""}`; return (
+{post.upvotes}
{maybePluralize(post.comments, "comment")}
{topic}