My app is reading data from multiple tables, then displays them in context and interconnected. To be able to react to user changes I’m using the useRecords hook, so that updates propagate to the app.
When searching why the app loads so slowly I realized that it starts over and over again, with each useRecords hook. Is there a way/pattern to avoid this, while still being able to read all the necessary table data?
My code:
...
const base = useBase();
// get all necessary Airtable tables
const tables = React.useMemo(() => {
return {
productTable: base.getTableByNameIfExists(Constants.PRODUCTS_TABLE_NAME),
costTable: base.getTableByNameIfExists(Constants.COST_TABLE_NAME),
contactsTable: base.getTableByNameIfExists(Constants.CONTACTS_TABLE_NAME),
conversionTable: base.getTableByNameIfExists(Constants.CONVERSIONS_TABLE_NAME),
contributorTable: base.getTableByNameIfExists(Constants.CONTRIBUTORS_TABLE_NAME),
};
}, [base]);
console.log('tables have been connected...')
const conversions = useRecords(tables.conversionTable);
console.log('conversions data has been read...')
const contributors = useRecords(tables.contributorTable);
console.log('contributor data has been read...')
const costs = useRecords(tables.costTable);
console.log('tracker data has been read...')
const products = useRecords(tables.productTable);
console.log('product data has been read...')
const vendors = useRecords(tables.contactsTable);
console.log('vendor data has been read...')
...
Console Output:
tables have been connected...
...
tables have been connected...
conversions data has been read...
...
tables have been connected...
conversions data has been read...
contributor data has been read...
...
tables have been connected...
conversions data has been read...
contributor data has been read...
tracker data has been read...
...
tables have been connected...
conversions data has been read...
contributor data has been read...
tracker data has been read...
product data has been read...
...
tables have been connected...
conversions data has been read...
contributor data has been read...
tracker data has been read...
product data has been read...
vendor data has been read...
...
