Files
reactfire/docs/reference.md
2019-07-09 16:37:32 -07:00

9.6 KiB

Reference Docs

Table of Contents

Providers

FirebaseAppProvider

A React Context Provider that allows the useFirebaseApp hook to pick up the firebase object.

Sample usage

const firebaseConfig = {
  /* web app config from Firebase console */
};

<FirebaseAppProvider firebaseConfig={firebaseConfig} initPerformance>
  <App />
</FirebaseAppProvider>;

Props

Prop Type Description
config Object the web app config object usually passed to initializeApp
initPerformance bool Whether or not to initialize Firebase Performance Monitoring

Hooks

useFirebaseApp

When called from a component nested inside a FirebaseAppProvider, useFirebaseApp returns the root Firebase object.

IMPORTANT: By default, useFirebaseApp returns a firebase object without any products attached to it (e.g. you can't call firebase.firestore(). To do that, you need to import 'firebase/firestore' or any other Firebase feature as needed)

Returns

firebase

useUser

Get the user that is currently signed in.

Throws a Promise by default

Parameters

Parameter Type Description
auth ? Auth [optional] auth object. If not provided, useUser will use useFirebaseApp to find the Auth object.
options ? ReactFireOptions Options. This hook will not throw a Promise if you provide startWithValue.

Returns

User

useFirestoreDoc

Listen to a Firestore Document.

Throws a Promise by default

Parameters

Parameter Type Description
ref DocumentReference A reference to the document you want to listen to
options ? ReactFireOptions Options. This hook will not throw a Promise if you provide startWithValue.

Returns

DocumentSnapshot

useFirestoreCollection

Listen to a Firestore Collection.

Throws a Promise by default

Parameters

Parameter Type Description
ref CollectionReference A reference to the collection you want to listen to
options ? ReactFireOptions Options. This hook will not throw a Promise if you provide startWithValue.

Returns

QuerySnapshot

useDatabaseObject

Listen to a Realtime Database Object.

Throws a Promise by default

Parameters

Parameter Type Description
ref Reference A reference to the object you want to listen to
options ? ReactFireOptions Options. This hook will not throw a Promise if you provide startWithValue.

Returns

QueryChange

useDatabaseList

Listen to a Realtime Database list.

Throws a Promise by default

Parameters

Parameter Type Description
ref Reference A reference to the list you want to listen to
options ? ReactFireOptions Options. This hook will not throw a Promise if you provide startWithValue.

Returns

QueryChange[]

useStorageTask

Listen to a Storage UploadTask

Throws a Promise by default

Parameters

Parameter Type Description
task UploadTask
ref Reference
options ? ReactFireOptions

Returns

UploadTaskSnapshot

useStorageDownloadURL

Subscribe to a storage blob's download URL

Throws a Promise by default

Parameters

Parameter Type Description
ref Reference
options ? ReactFireOptions

Returns

string

Components

AuthCheck

Renders children if a user is signed in and meets the required claims. Renders fallback otherwise.

Props

Property Type
auth Auth
children React.Component
fallback React.Component
requiredClaims Object

SuspenseWithPerf

Starts a Firebase Performance Monitoring trace and ends it when suspense stops suspending.

Props

Property Type
children React.Component
fallback React.Component
firePerf ? any
traceId string

ReactFireOptions

Property Type
startWithValue any