Avoid infinite loop loading the list of guests (#62)
Some checks failed
Check usage of free licenses / build-static-assets (push) Successful in 30s
Build Nginx-based docker image / build-static-assets (push) Failing after 2m17s
Playwright Tests / test (push) Successful in 3m1s

Reviewed-on: #62
Co-authored-by: Manuel Bustillo <bustikiller@bustikiller.com>
Co-committed-by: Manuel Bustillo <bustikiller@bustikiller.com>
This commit is contained in:
Manuel Bustillo 2024-10-27 11:10:45 +00:00 committed by bustikiller
parent 7c6f00155a
commit 8aef089a7e

View File

@ -1,20 +1,15 @@
'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")
export default function guestsTable() {
function loadGuests() {
fetch("http://localhost:3001/guests.json")
.then((response) => response.json())
.then((data) => {
return data.data.map((record: any) => {
setGuests(data.data.map((record: any) => {
return ({
id: record.id,
name: record.attributes.name,
@ -22,10 +17,15 @@ export default async function guestsTable() {
group_name: record.attributes.group_name,
status: record.attributes.status
});
});
}));
}, (error) => {
return [];
});
}
const [guests, setGuests] = useState<Array<Guest>>([]);
guests.length === 0 && loadGuests();
return (
<div className="w-full relative overflow-x-auto shadow-md sm:rounded-lg">