Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for new Firestore "collection group" query #52

Open
sampl opened this issue Jun 23, 2019 · 2 comments
Open

Support for new Firestore "collection group" query #52

sampl opened this issue Jun 23, 2019 · 2 comments

Comments

@sampl
Copy link
Contributor

sampl commented Jun 23, 2019

馃憢

Would love to use the new Firestore collection group feature in react-firestore

https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query

@sampl
Copy link
Contributor Author

sampl commented Jun 23, 2019

something like

import Firebase from 'firebase/app'	
import React from 'react'	

 class FirestoreCollectionGroup extends React.Component {	

   state = {	
    isLoading: true,	
    error: null,	
    data: null,
    snapshot: null,
  }	

  componentDidMount() {	
    this.unsubscribe = Firebase.firestore()	
      .collectionGroup(this.props.path)	
      .where(this.props.filter[0], this.props.filter[1], this.props.filter[2])	
      .onSnapshot(this.handleBoard, this.handleError)	
  }	

   componentWillUnmount() {	
    if (this.unsubscribe) {	
      this.unsubscribe()	
    }	
  }	

   handleBoard = snapshot => {	
    this.setState({	
      isLoading: false,
      data: snapshot.docs.map(docSnap => docSnap.data()),
      snapshot,
      error: null,	
    })	
  }	

   handleError = error => {	
    this.setState({	
      isLoading: false,	
      data: null,
      snapshot: null,
      error,	
    })	
  }	

   render() {	
    return this.props.children(this.state)	
  }	
}	

export default FirestoreCollectionGroup

@sampl
Copy link
Contributor Author

sampl commented Jun 23, 2019

Actually just ran into a problem with collectionGroups and may not use them after all, but leaving open in case others have a need

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant