Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/bindings-typescript/src/react/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export function useTable<TableDef extends UntypedTableDef>(
): [readonly Prettify<RowType<TableDef>>[], boolean] {
type UseTableRowType = RowType<TableDef>;
const tableName = tableDef.name;
const accessorName = tableDef.accessorName;
let whereClause: Expr<ColumnsFromRow<UseTableRowType>> | undefined;
if (
whereClauseOrCallbacks &&
Expand Down Expand Up @@ -313,15 +314,15 @@ export function useTable<TableDef extends UntypedTableDef>(
if (!connection) {
return [[], false];
}
const table = connection.db[tableName];
const table = connection.db[accessorName];
const result: readonly Prettify<UseTableRowType>[] = whereClause
? (Array.from(table.iter()).filter(row =>
evaluate(whereClause, row as UseTableRowType)
) as Prettify<UseTableRowType>[])
: (Array.from(table.iter()) as Prettify<UseTableRowType>[]);
return [result, subscribeApplied];
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [connectionState, tableName, whereKey, subscribeApplied]);
}, [connectionState, accessorName, whereKey, subscribeApplied]);

useEffect(() => {
const connection = connectionState.getConnection()!;
Expand Down Expand Up @@ -412,7 +413,7 @@ export function useTable<TableDef extends UntypedTableDef>(
return () => {};
}

const table = connection.db[tableName];
const table = connection.db[accessorName];
table.onInsert(onInsert);
table.onDelete(onDelete);
table.onUpdate?.(onUpdate);
Expand All @@ -426,7 +427,7 @@ export function useTable<TableDef extends UntypedTableDef>(
// eslint-disable-next-line react-hooks/exhaustive-deps
[
connectionState,
tableName,
accessorName,
whereKey,
callbacks?.onDelete,
callbacks?.onInsert,
Expand Down
Loading