0.2.3 • Published 5 years ago

react-cached-firestore v0.2.3

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

react-cached-firestore

Installation

Using npm:

$ npm install --save https://github.com/gkkachi/react-cached-firestore.git

Usage

App.tsx

import React from 'react'
import * as firebase from 'firebase/app';
import Provider from 'react-cached-firestore'
import MyApp from './MyApp.tsx'

const app = firebase.initializeApp({ ... })

const App: React.FC = () => {

    ...
    
    return (
        <Provider app={app}>
            <MyApp />
        </Provider>
    )
}

AmazingApp.tsx

import { useDocumentsContext } from 'react-cached-firestore'

const AmazingApp: React.FC = () => {
    const path: string = 'PATH/TO/DOCUMENT'
    const { getDoc } = useDocumentsContext()

    // if you want the latest data,
    const snap = getDoc(path)

    // if you do not need the latest data,
    // const snap = getDoc(path, false)
    
    const snap = docs[path]
    
    if (snap) {
        // do something
    } else {
        // do something
    }
    
    ...
}
0.2.3

5 years ago

0.2.2

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago