react-firebase-firestore
a connection library for react and firebase
this works similar to react-firebase but it works for firestore (i tried to PR this in and got ignored.)
this library includes logic to do the path setting for you, so docs/lskdl2lk322l4j/abc
gets parsed into document('docs').collection('lskdl2lk322l4j').document('abc')
and so on.
The full API of Firestore is available to you in a ref
variable, so you will have to use their preferred method names. see below example.
Install
npm install --save react-firebase-firestore
Usage
secrets.js
:
var firebase = ;// Required for side-effects;var config = // copy from firebase console https://console.firebase.google.com/ apiKey: "" authDomain: "" databaseURL: "" projectId: "" storageBucket: "" messagingSenderId: "";firebase;const firestore = firebase;;
index.js
:
import React from "react";import ReactDOM from "react-dom";import App from "./ui/layouts/App/App";import Provider from "react-firebase"; import firebase firestore from "./secrets"; ReactDOM;
any given container:
import React from "react";import connect from "react-firebase-firestore"; Component // ... const mapFirebaseToProps = props ref propsdoc ? : ; mapFirebaseToPropsDocumentEditor;
alternative example showing a reactive query as well as a delete operation:
// as above const mapFirebaseToProps = props ref rawdocs: "documents" { if ; }; mapFirebaseToPropsDocuments;
react-firebase
to react-firebase-firestore
converting codebases from from Firebase to Firestore, simply rename:
remove
todelete
push
toadd
update
is stillupdate
License
MIT © sw-yx