Skip to content

React Native - Hooks

Typed hooks for subscribing to Firestore documents and collections in React Native applications, backed by React Native Firebase.

Usage

The API is the same as the React hooks, but uses @react-native-firebase/firestore under the hood.

ts
import { useDocument } from "@typed-firestore/react-native";

function UserProfile({ userId }: { userId: string }) {
  const [user, isLoading] = useDocument(refs.users, userId);

  if (isLoading) return <ActivityIndicator />;

  return <Text>{user.data.displayName}</Text>;
}

TIP

Firestore types from @react-native-firebase/firestore can be awkward to work with. This library re-exports commonly needed types like CollectionReference, DocumentReference, and DocumentData in a more convenient format.

ts
import type {
  CollectionReference,
  DocumentReference,
} from "@typed-firestore/react-native";

API Reference

HookDescription
useDocumentUse a document and subscribe to changes
useDocumentDataUse only the data part of a document and subscribe to changes
useDocumentMaybeUse a document that might not exist
useDocumentDataMaybeUse only the data part of document that might not exist
useDocumentOnceUse a document once and do not subscribe for changes
useDocumentDataOnceUse only the data part of a document once and do not subscribe for changes
useSpecificDocumentUse a document by ref and subscribe to changes
useSpecificDocumentDataUse only the data part of a document by ref
useSpecificDocumentMaybeUse a document by ref that might not exist
useSpecificDocumentDataMaybeUse only the data part of a document by ref that might not exist
useSpecificDocumentOnceUse a document by ref once
useSpecificDocumentDataOnceUse only the data part of a document by ref once
useCollectionQuery a collection and subscribe for changes
useCollectionOnceQuery a collection once
useCollectionMaybeQuery a collection, never throw
useCollectionCountOnceQuery the number of documents

Released under the Apache-2.0 License.