Hi Kamille!
Under the hood, all that useRecords
does is something like this:
useLoadable(query);
useWatchable(query, ['records', 'cellValues', 'recordColors']);
return query.records;
(it’s actually a little more complicated than that, but that’s the essence of it - you can check out the source code here if you’re interested!)
Whilst useRecords
only accepts a single query/table/view etc, the lower-level useLoadable
and useWatchable
hooks accept arrays. That means you could do something like this:
// get linked record queries for every record:
const linkedRecordQueries = selectedRecords.map(
record => record.selectLinkedRecordsFromCell(fieldName),
);
// load all the linked record queries:
useLoadable(linkedRecordQueries);
// rerender whenever any of the records in those queries change:
useWatchable(linkedRecordQueries, r'records', 'cellValues', 'recordColors']);
// get one big array with all the linked records:
const allLinkedRecords = linkedRecordQueries
.map(query => query.records)
.flat();
Creating lots of query results very dynamically like this though probably won’t be great for performance on large tables though.
Relevant docs links:
Hope this helps!
Hi Kamille!
Under the hood, all that useRecords
does is something like this:
useLoadable(query);
useWatchable(query, ['records', 'cellValues', 'recordColors']);
return query.records;
(it’s actually a little more complicated than that, but that’s the essence of it - you can check out the source code here if you’re interested!)
Whilst useRecords
only accepts a single query/table/view etc, the lower-level useLoadable
and useWatchable
hooks accept arrays. That means you could do something like this:
// get linked record queries for every record:
const linkedRecordQueries = selectedRecords.map(
record => record.selectLinkedRecordsFromCell(fieldName),
);
// load all the linked record queries:
useLoadable(linkedRecordQueries);
// rerender whenever any of the records in those queries change:
useWatchable(linkedRecordQueries, r'records', 'cellValues', 'recordColors']);
// get one big array with all the linked records:
const allLinkedRecords = linkedRecordQueries
.map(query => query.records)
.flat();
Creating lots of query results very dynamically like this though probably won’t be great for performance on large tables though.
Relevant docs links:
Hope this helps!
Thank you!! for both the quick response and the warning of performance.