import { useEffect, useState } from 'react'; import { useParams } from 'react-router'; import { Link } from 'react-router-dom'; import { IEvent } from './Event'; import EventCreatorLink from './EventCreatorLink'; import EventStream from './EventStream'; import GroupSettingsLink from './GroupSettingsLink'; import UILink from './UILink'; export type IGroup = { id: number; events: IEvent[]; name: string; }; export default function Group() { const { id } = useParams<{ id: string }>(); const [loading, setLoading] = useState(true); const [group, setGroup] = useState(null); const [events, setEvents] = useState([]); useEffect(() => { setLoading(true); fetch('http://localhost:5000/api/groups/' + id) .then((response) => response.json()) .then(setGroup) .finally(() => setLoading(false)); fetch('http://localhost:5000/api/groups/' + id + '/events') .then((response) => response.json()) .then(setEvents); }, [id]); if (!group && !loading) { return (

Group Not Found

Home
); } if (!group) { return null; } const { name } = group; console.log({ events }); return (

{name}

Home



); }