react-firebase-context icon indicating copy to clipboard operation
react-firebase-context copied to clipboard

Multiple queries in one <Firestore>

Open wojciech111 opened this issue 5 years ago • 0 comments

First thanks for simple and super useful solution. It looks awesome but I found problem when I try to get two different documents to one page. I know that noSQL db should be optimized to access only one doc but there are cases when this just don't feel right.

Than I need to do workaround like this:

const DataProvider = ({ journeyId,personId,children }) => {
    return (
        <Suspense fallback={<p>Loading user data...</p>}>
            <Firestore
                query={({ firestore }) => firestore.collection('journeys').doc(journeyId)}
            >
                {({ data: journey }) => (
                    <Firestore
                        query={({ firestore }) => firestore.collection('persons').doc(personId)}
                    >
                        {({ data: person,firestore }) => (
                            <Fragment>
                                {children({ journey,person,firestore })}
                            </Fragment>
                        )}
                    </Firestore>
                )}
            </Firestore>
        </Suspense>
    );
};

This approach seems to have one minus that on journeys change the lower level component got rerendered and fetch again the same person document. I glanced at your implementation and saw that you are hashing queries. This looks like adding queries::Array parameter to Firestore shouldn't be super challenging. Give me a sign if I'm not missing anything. Maybe we can cooperate in working out the solution.

Cheers and thx again

btw. support for fetching multiple docs by id will be possible easily

wojciech111 avatar Jun 17 '19 07:06 wojciech111