Skip to content

React hooks for google cloud firestore database

Notifications You must be signed in to change notification settings

armedi/makefire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

makefire

This is a simple React hooks for google cloud firestore database.

Requirements

  1. Create a firebase project in firebase console
  2. 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) {
  // subscribing to document 'bob' in 'users' collection
  const { data, loading, error } = useDocument('users/bob')

  // subscribing to 'users' collection
  const { data, loading, error } = useCollection('users')

  // subscribing to 'users' collection with additional queries
  const { data, loading, error } = useCollection('users', [['age', '>=', 21], ['location', '==', 'Jakarta']])
  
  ...
  );
}

About

React hooks for google cloud firestore database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published