makefire
This is a simple React hooks for google cloud firestore database.
Requirements
- Create a firebase project in firebase console
- Obtain firebase configuration for the project. You can find how to get the configuration on this link
Installation
npm install firebase makefire
Usage
Setup firebase with your app configuration and then create useDocument
and useCollection
hooks with makefire
import * as firebase from 'firebase/app'
import "firebase/firestore";
import makefire from 'makefire'
const firebaseConfiguration = {
apiKey: '### FIREBASE API KEY ###',
authDomain: '### FIREBASE AUTH DOMAIN ###',
projectId: '### CLOUD FIRESTORE PROJECT ID ###'
};
firebase.initializeApp(firebaseConfiguration)
const db = firebase.firestore()
const { useDocument, useCollection } = makefire(db)
Now you can use them on your components. Insert the path for the collection or document in database as the first argument for the hooks.
function CoolComponent(props) {
const { data, loading, error } = useDocument('users/bob')
const { data, loading, error } = useCollection('users')
const { data, loading, error } = useCollection('users', [['age', '>=', 21], ['location', '==', 'Jakarta']])
...
);
}