Open jihea-park opened 4 months ago
Getting same issue when using alert dialog in Data Table actions. @jiheapark do you find any solution ?
I have the same issue. It happens with pretty much any shadcn component that has an open state. I've tried tracking the state and passing it to the component that houses the table, it works, but the component briefly flashes closed and back open, which isn't a good experience.
For me, this doesn't happen on an async request from the table, it happens on a background auth token request. So it seems any re-render is causing this issue.
After some troubleshooting the solution is to memoize the column. https://stackoverflow.com/questions/62666841/using-react-table-with-react-modal If you memorize the column definition like this in your example, then any shadcn component that uses open states will work fine:
const columns = useMemo(() => [
{
accessorKey: 'id',
header: 'ID',
},
{
accessorKey: 'userId',
header: 'User Id',
},
{
accessorKey: 'title',
header: 'Title',
},
{
accessorKey: 'body',
header: 'Body',
},
{
header: 'Action',
enableSorting: false,
cell: ({ row }: { row: any }) => {
const id = String(row?.original?.id);
return (
<ConfirmWithInputDialog
title={'Delete'}
content={
<>
<div className="text-primary">{id} is to be deleted.</div>
<div className="text-destructive">Really delete?</div>
</>
}
input={id}
okText={'Delete'}
okVariant="destructive"
onOk={() => onDelete?.(id)}
>
<Button size="sm" variant="destructive">
Delete
</Button>
</ConfirmWithInputDialog>
);
},
},
], []);
@shiftcontrol-dan It works good. Thank you!!!
Describe the bug
The Dialog closes after asynchronous function in the DataTable. I think after
onDelete
, the dialog still opens. But it closes.Affected component/components
Dialog, DataTabe
How to reproduce
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
Before submitting