import { Button, Dialog, DialogContent, DialogTitle } from '@mui/material'; import { nanoid } from 'nanoid'; import { useCallback, useEffect, useState } from 'react'; import { Item, ItemComment } from '../../../../data/types'; import { ItemsTableRowAction } from '../Items/ItemsTableRowAction'; import CreateComment from './CreateComment/CreateComment'; import ItemData from './ItemData'; interface ItemDialogProps { item: Item; open: boolean; handleClose: () => void; } export default function ItemDialog({ item, open, handleClose }: ItemDialogProps) { const [comments, setComments] = useState([]); const [formKey, setFormKey] = useState(() => nanoid()); const fetchData = useCallback(async () => { try { const comments = await ItemsTableRowAction(item.id); setComments(comments); } catch (error) { console.error("Couldn't fetch comments."); } }, [item]); useEffect(() => { fetchData(); }, [fetchData, formKey]); return ( Item: {item.name} ); }