import React, { useState, useEffect } from 'react'; const Pools = (props) => { const [state, setState] = useState({ Pools: [ { id: 1, pool_title: 'TJ Carpool', pool_text: 'Carpool from TJ track to homes', start_time: '4/10/2021 3:00 PM', end_time: '4/10/2021 4:00 PM', capacity: 2, participants: [], comments: [ 'What is the covid vaccination status of all the participants?', ], }, { id: 2, pool_title: 'TJ Carpool', pool_text: 'Carpool from TJ track to homes', start_time: '4/10/2021 3:00 PM', end_time: '4/10/2021 4:00 PM', capacity: 2, participants: [], comments: [ 'What is the covid vaccination status of all the participants?', ], }, { id: 3, pool_title: 'TJ Carpool', pool_text: 'Carpool from TJ track to homes', start_time: '4/10/2021 3:00 PM', end_time: '4/10/2021 4:00 PM', capacity: 2, participants: [], comments: [ 'What is the covid vaccination status of all the participants?', ], }, { id: 4, pool_title: 'TJ Carpool', pool_text: 'Carpool from TJ track to homes', start_time: '4/10/2021 3:00 PM', end_time: '4/10/2021 4:00 PM', capacity: 2, participants: [], comments: [ 'What is the covid vaccination status of all the participants?', ], }, ], }); const callAPI = () => { fetch(`${process.env.REACT_APP_API_ENDPOINT}/pools/`) .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 (
Capacity: {Pool.participants.length} / {Pool.capacity}
Start Time: {Pool.start_time}
End Time: {Pool.end_time}
{maybePluralize(Pool.comments.length, 'comment')}