For the sake of handeling infinite scroll, I created a function that add conditions to the query according to the desired behavior:
const queryDocs = async (behavior: string = 'start', limit: number = 25) => { let augmentedQuery: Query<DocumentData> | CollectionReference<DocumentData> = query try { if (behavior === 'start' || behavior === 'limited') { augmentedQuery = augmentedQuery.limit(limit) } if (behavior === 'next'&& lastItem) { augmentedQuery = augmentedQuery.limit(limit).startAfter(lastItem) } const snapshot = await augmentedQuery.get() if (behavior === 'start' || behavior === 'next') { setLastItem(snapshot.docs[snapshot.docs.length - 1]) } return snapshot } catch (error) { throw functionError(error, 'queryDocs', [behavior, limit], 'useCollection') } }
I get the following error:
on queryData("start",1) in module useCollection: Attempted to assign to readonly property.
Can we take take a previous query and add a .where or .limit?
Is there a solution to handle conditional queries?
Thanks
Edit: As Doug stated in the discussion, it is perfectly possible to chain queries like this. The error comes from another source. This code was into a shared package that was recompiled from TypeScript to ES6 and then used in React Native. After merging all the code into the React Native directory the error changed. I had a request to create a composite index with the link to do so, what is quite straightforward.