makefire

0.4.1 • Public • Published

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']])
  
  ...
  );
}

Package Sidebar

Install

npm i makefire

Weekly Downloads

0

Version

0.4.1

License

MIT

Unpacked Size

33.8 kB

Total Files

9

Last publish

Collaborators

  • armedi