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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@humancollective/web-firebase

v1.2.3

Published

This project contains some of the hooks we find useful when working with Firebase. They are all written in TypeScript and use the popular `react-firebase-hooks` package as a base.

Downloads

9

Readme

@humancollective/web-firebase

This project contains some of the hooks we find useful when working with Firebase. They are all written in TypeScript and use the popular react-firebase-hooks package as a base.

Installation

npm install @humancollective/web-firebase

or

yarn add @humancollective/web-firebase

...WithArgs Hooks

Often when working with Firebase, you want to query a document or collection with a path that has some dynamic parts. These parts may only become available after initial load. For these cases, we've created hooks to wait until all parts are defined and then generating the reference. These hooks also take care of expanding the snapshots and including their IDs in the result.

useDocumentWithArgs

Let's say you want to create a hook to use a user's profile document, but the user's ID is only available after authentication. This would usually require more than one hook to manage, but we find it much simpler to use our ...WithArgs hooks.

import { useDocumentWithArgs } from 'web-firebase';

const useProfile = (userId?: string) =>
  useDocumentWithArgs<Profile>(u => doc(firestore, 'user-profiles', u), [
    userId,
  ]);

This function will create the document reference only once the userId is available. If the userId changes, the document reference will be updated.

The return type can be used to determine the state of the document:

  • undefined - This is the initial state. Either the userId is not yet available, or the document is still loading. In any successful case, this will be a temporary state. It's often valuable to display a load indicator here.
  • null - The query has run and has returned that the document does not exist. It's useful to display a "not found" message here.
  • WithId<T = any> - If the document is found, the hook will return the expanded document data with the ID as a key (id). When the document is updated, this will be updated as well in realtime.

useCollectionWithArgs

This function is very similar to useDocumentWithArgs but it returns an array of expanded values. For example, if you want to query a collection of messages on a specific thread, you could create a hook like this:

import { useDocumentWithArgs } from 'web-firebase'

const useMessages = (threadId?: string) => useDocumentWithArgs<Profile>(
  (t) => query(
    collection(firestore, 'threads', t, 'messages),
    orderBy('createdAt', 'desc'),
  ),
  [threadId],
)

The return type can be used to determine the state of the query:

  • undefined - This is the initial state. Either the threadId is not yet available, or the query is still loading. In any successful case, this will be a temporary state. It's often valuable to display a load indicator here.
  • [] (empty array) - The query has run and has returned that the collection is empty. You might want to display an empty state in this case.
  • WithId<T = any>[] - If the collection is populated, the hook will return the list of expanded documents each with its ID as a key (id). When the collection is updated, this list will be updated as well in realtime.