Usage

Components

  • FirestoreProvider

  • FirestoreCollection

  • FirestoreDocument

  • FirestoreMutation

  • FirestoreBatchedWrite

Firestore Provider

Place a FirestoreProvider component at the top level of your app.

import { FirestoreProvider } from '@react-firebase/firestore'
// Before
const App = () => {
    return <div>
        This is my app
    </div>
}

// After
const App = () => {
    return (
        <FirestoreProvider {...config} firebase={firebase}>
            <div>
                This is my app
            </div>
        </FirestoreProvider>
    )
}

If you need to authenticate to access your data, check out @react-firebase/auth

Firestore Collection Example

Firestore Document Example

Firestore Mutation

The FirestoreMutation allows you to render components that run Firebase mutations (update, set, add).

A setMutation function that returns a promise is provided to the children function.

FirebaseDatabaseMutation needs 3 props :

  • path: string

  • operation: "update" | "set" | "add"

  • children:

    ( { runMutation: (value:any, options?:any) => Promise<{key?:string}> } ) => ReactNode

Upsert (update or insert) data to Firestore example

Batched Writes

Schedule a mutation with addMutationToBatch, and commit your changes with commit.

Complete Example

Last updated