Avoid infinite loop loading the list of guests (#62)
Reviewed-on: #62 Co-authored-by: Manuel Bustillo <bustikiller@bustikiller.com> Co-committed-by: Manuel Bustillo <bustikiller@bustikiller.com>
This commit is contained in:
		
							parent
							
								
									7c6f00155a
								
							
						
					
					
						commit
						8aef089a7e
					
				@ -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 clsx from 'clsx';
 | 
				
			||||||
 | 
					import React, { useState, useEffect } from 'react';
 | 
				
			||||||
 | 
					import { Guest } from '@/app/lib/definitions';	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function TableHeader() {
 | 
					export default function guestsTable() {
 | 
				
			||||||
  
 | 
					  function loadGuests() {
 | 
				
			||||||
}
 | 
					    fetch("http://localhost:3001/guests.json")
 | 
				
			||||||
 | 
					      .then((response) => response.json())
 | 
				
			||||||
export default async function guestsTable() {
 | 
					      .then((data) => {
 | 
				
			||||||
 | 
					        setGuests(data.data.map((record: any) => {
 | 
				
			||||||
  let guests: Guest[] = await fetch("http://localhost:3001/guests.json")
 | 
					          return ({
 | 
				
			||||||
    .then((response) => response.json())
 | 
					            id: record.id,
 | 
				
			||||||
    .then((data) => {
 | 
					            name: record.attributes.name,
 | 
				
			||||||
      return data.data.map((record: any) => {
 | 
					            email: record.attributes.email,
 | 
				
			||||||
        return ({
 | 
					            group_name: record.attributes.group_name,
 | 
				
			||||||
          id: record.id,
 | 
					            status: record.attributes.status
 | 
				
			||||||
          name: record.attributes.name,
 | 
					          });
 | 
				
			||||||
          email: record.attributes.email,
 | 
					        }));
 | 
				
			||||||
          group_name: record.attributes.group_name,
 | 
					      }, (error) => {
 | 
				
			||||||
          status: record.attributes.status
 | 
					        return [];
 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    }, (error) => {
 | 
					  }
 | 
				
			||||||
      return [];
 | 
					
 | 
				
			||||||
    });
 | 
					  const [guests, setGuests] = useState<Array<Guest>>([]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  guests.length === 0 && loadGuests();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className="w-full relative overflow-x-auto shadow-md sm:rounded-lg">
 | 
					    <div className="w-full relative overflow-x-auto shadow-md sm:rounded-lg">
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user