npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@valian/zustand-firestore

v1.3.2

Published

zustand store for firestore queries and document snapshots

Readme

@valian/zustand-firestore

Zustand stores for Firebase Firestore document and query snapshots with real-time updates and TypeScript support.

npm version License: MIT

Installation

pnpm add @valian/zustand-firestore

Peer dependencies

Make sure these peers are installed in your app:

  • react ^18 || ^19
  • react-dom ^18 || ^19
  • firebase ^11 || ^12
  • rxjs ^7.8.0
  • zustand ^5

Usage

useQueryStore

Subscribe to a Firestore query and read state from a Zustand store.

import { useQueryStore } from '@valian/zustand-firestore'
import { useStore } from 'zustand'
import { collection, query, where } from 'firebase/firestore'
import { db } from './firebase'

interface Todo {
  id: string
  title: string
  completed: boolean
  createdAt: Date
}

export function TodoList() {
  const todosQuery = query(
    collection(db, 'todos'),
    where('completed', '==', false),
  )

  const store = useQueryStore<Todo>({
    query: todosQuery,
    onError: (error) => console.error('Firestore error:', error),
  })

  const { data, isLoading, empty, size, hasError } = useStore(store)

  if (isLoading) return <div>Loading...</div>
  if (hasError) return <div>Error loading todos</div>
  if (empty) return <div>No todos</div>

  return (
    <ul>
      {data.map((todo, index) => (
        <li key={index}>{todo.title}</li>
      ))}
      <li>Total: {size}</li>
    </ul>
  )
}

You can pass Firestore SnapshotListenOptions as props (e.g. includeMetadataChanges: true).

useDocumentStore

Subscribe to a single document and read its state from a Zustand store.

import { useDocumentStore } from '@valian/zustand-firestore'
import { useStore } from 'zustand'
import { doc } from 'firebase/firestore'
import { db } from './firebase'

interface User {
  name: string
  email: string
  avatar?: string
  createdAt: Date
}

export function UserProfile({ userId }: { userId: string }) {
  const ref = doc(db, 'users', userId)
  const store = useDocumentStore<User>({
    ref,
    onError: (error) => console.error('Firestore error:', error),
  })

  const { data, isLoading, exists, hasError } = useStore(store)

  if (isLoading) return <div>Loading...</div>
  if (hasError) return <div>Error loading user</div>
  if (!exists) return <div>User not found</div>

  return (
    <div>
      <h1>{data?.name}</h1>
      <p>{data?.email}</p>
    </div>
  )
}

Conditional subscription

Disable the subscription by passing null or undefined.

export function MaybeUserProfile({ userId }: { userId?: string }) {
  const ref = userId ? doc(db, 'users', userId) : null
  const store = useDocumentStore<User>({ ref })
  const { data, isLoading, exists, disabled } = useStore(store)

  if (disabled) return <div>Select a user</div>
  if (isLoading) return <div>Loading...</div>
  if (!exists) return <div>User not found</div>

  return <div>{data?.name}</div>
}

API (shapes)

Both stores expose the same state shapes as @valian/rxjs-firebase:

  • Query store state includes: data[], size, empty, isLoading, hasError, disabled, and snapshot.
  • Document store state includes: data?, exists?, isLoading, hasError, disabled, and snapshot.

License

MIT © Valian

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please open an issue in the repository.