From 8aef089a7ec67b7d01a87663c686d6d93f741e41 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 27 Oct 2024 11:10:45 +0000 Subject: [PATCH] Avoid infinite loop loading the list of guests (#62) Reviewed-on: https://gitea.bustikiller.com/bustikiller/wedding-planner-frontend/pulls/62 Co-authored-by: Manuel Bustillo Co-committed-by: Manuel Bustillo --- app/ui/guests/table.tsx | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/app/ui/guests/table.tsx b/app/ui/guests/table.tsx index 0f31a0c..f9094ec 100644 --- a/app/ui/guests/table.tsx +++ b/app/ui/guests/table.tsx @@ -1,31 +1,31 @@ -'use client' +'use client'; -import { Guest } from '@/app/lib/definitions'; -import SkeletonRow from './skeleton-row'; -import { Suspense } from 'react'; import clsx from 'clsx'; +import React, { useState, useEffect } from 'react'; +import { Guest } from '@/app/lib/definitions'; -export function TableHeader() { - -} - -export default async function guestsTable() { - - let guests: Guest[] = await fetch("http://localhost:3001/guests.json") - .then((response) => response.json()) - .then((data) => { - return data.data.map((record: any) => { - return ({ - id: record.id, - name: record.attributes.name, - email: record.attributes.email, - group_name: record.attributes.group_name, - status: record.attributes.status - }); +export default function guestsTable() { + function loadGuests() { + fetch("http://localhost:3001/guests.json") + .then((response) => response.json()) + .then((data) => { + setGuests(data.data.map((record: any) => { + return ({ + id: record.id, + name: record.attributes.name, + email: record.attributes.email, + group_name: record.attributes.group_name, + status: record.attributes.status + }); + })); + }, (error) => { + return []; }); - }, (error) => { - return []; - }); + } + + const [guests, setGuests] = useState>([]); + + guests.length === 0 && loadGuests(); return (