bugfix: use row id instead of index to keep row selection after table… (#120)

* bugfix: use row id instead of index to keep row selection after table update

* bugfix: await creation before displaying the row and refetching
This commit is contained in:
Sammy Teillet
2023-05-17 14:43:09 +02:00
committed by GitHub
parent 499752ed6b
commit 2facb383a2
2 changed files with 3 additions and 2 deletions

View File

@ -124,6 +124,7 @@ const Table = <TData extends { id: string }, SortField>(
getCoreRowModel: getCoreRowModel(),
enableRowSelection: true,
onRowSelectionChange: setInternalRowSelection,
getRowId: (row) => row.id,
});
const selectedRows = table.getSelectedRowModel().rows;

View File

@ -63,7 +63,7 @@ function People() {
}
}, [loading, setInternalData, data]);
const addEmptyRow = useCallback(() => {
const addEmptyRow = useCallback(async () => {
const newCompany: Person = {
id: uuidv4(),
firstname: '',
@ -75,7 +75,7 @@ function People() {
creationDate: new Date(),
city: '',
};
insertPerson(newCompany);
await insertPerson(newCompany);
setInternalData([newCompany, ...internalData]);
refetch();
}, [internalData, setInternalData, refetch]);