Help

Re: How to Get the selected record?

856 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Ashwin_P
6 - Interface Innovator
6 - Interface Innovator

This does not work. It throws some exceptions.

useLoadable(cursor);
useWatchable(cursor, ['activeTableId', 'selectedRecordIds']);
const table = base.getTableById(cursor.activeTableId);
const record = useRecordById(table, cursor.selectedRecordIds[0]);

This works. But is this the correct way to do it? Feels like there should be a much simpler way to do this.

useLoadable(cursor);
useWatchable(cursor, ['activeTableId', 'selectedRecordIds']);
const table = base.getTableById(cursor.activeTableId);
const queryResult = table.selectRecords();
let record = null;
try {
    record = queryResult.getRecordById(cursor.selectedRecordIds[0]);
} catch (e) {
    record = null;
}
1 Reply 1
Emma_Yeap
Airtable Employee
Airtable Employee

@Ashwin_P What version of the SDK are you using? Support for useRecordById(table, recordId) was added in 0.0.42 (you can view the changelog here).

If that doesn’t fix it, can you share what exceptions are being thrown?