react-cached-firestore
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

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
    }
    
    ...
}

Package Sidebar

Install

npm i react-cached-firestore

Weekly Downloads

1

Version

0.2.3

License

MIT

Unpacked Size

6.98 kB

Total Files

5

Last publish

Collaborators

  • gkkachi