I’m building a block which (should) allow users to select multiple records in Table A. I would like to get a set of each selected record’s linked Table B records. The problem I’m running in to I believe relates to using a hook within a loop.
Right now I’m using selectedRecords.map(record => {...} ).flat() to loop through each selected record. Within the loop, I’m using useRecords(record.selectLinkedRecordsFromCell(fieldName)) to get the linked records into a single array. This works but only if the user selects the same number of records each time, or cancels the current selection and starts over. Meaning if someone selects one record it works, if someone selects all records it works, but if someone changes the number of selected records by clicking and dragging or by using the selection boxes at the far left, React throws an error: Error: Rendered more/fewer hooks than during the previous render.
I think I could possible get around this if I could combine/collapse multiple record query results into one, then I’d only have to use useRecords() in one place and it could be a top level step. Is this possible? If not, is there some other workaround to get past this issue?
