# use-on-snapshot

> use-on-snapshot is custom hooks for onSnapshot of Firestore Database in Firebase.

Latest version **0.2.0** (published 2023-03-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install use-on-snapshot
pnpm add use-on-snapshot
yarn add use-on-snapshot
bun add use-on-snapshot
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2023-03-10 |
| First published | 2023-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | piro |
| Maintainers | piro0919 |
| Keywords | firebase, firestore, hooks, react, useOnSnapshot |

## Links

- npm: https://www.npmjs.com/package/use-on-snapshot
- Repository: https://github.com/piro0919/use-on-snapshot
- Homepage: https://github.com/piro0919/use-on-snapshot#readme
- Issues: https://github.com/piro0919/use-on-snapshot/issues
- npm.io page: https://npm.io/package/use-on-snapshot

## Dependencies (1)

- [usehooks-ts](https://npm.io/package/usehooks-ts.md) 2.9.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2023-03-10
- 0.1.1 — 2023-03-10
- 0.1.0 — 2023-03-10

## README

# use-on-snapshot

use-on-snapshot is custom hooks for onSnapshot of Firestore Database in Firebase.

## Features

- TypeScript support

## Installation

`npm i --save use-on-snapshot`

## Usage

### Firestore Example

```ts
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";

const firebaseConfig = {
  apiKey: process.env.FIREBASE_API_KEY,
  appId: process.env.FIREBASE_APP_ID,
  authDomain: process.env.FIREBASE_AUTH_DOMAIN,
  messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
  projectId: process.env.FIREBASE_PROJECT_ID,
  storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

export default db;
```

### Get Document Example

```ts
import { DocumentReference, doc } from "firebase/firestore";
import db from "libs/db";

const { data, loading, error } = useOnSnapshot<DocumentReference, Hoge>({
  firestore: db,
  paths: ["hoges", "hogeId"],
  type: "reference",
});
```

### Get Collection Example

```ts
import { CollectionReference, collection } from "firebase/firestore";
import db from "libs/db";

const { data, loading, error } = useOnSnapshot<CollectionReference, Fuga>(
  {
    firestore: db,
    paths: ["hoges", "hogeId", "fugas],
    type: "query",
  },
);
```

---
_Source: https://npm.io/package/use-on-snapshot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
