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

react-firestarter

v2.0.2

Published

Firebase Components for React

Downloads

7

Readme

react-firestarter

Firebase Components for React

NPM styled with prettier Build Status Coverage Status

Install

npm install --save react-firestarter

Usage

Authentication

import React from 'react';

import { AuthProvider, Authenticator } from 'react-firestarter';

function Auth() {
  return (
    <AuthProvider fireauth={firebase.auth()}>
      <Authenticator onSuccess={onSuccess} onError={onError}>
        {({ isAuthenticated, signup, login, logout }) => {
          if (isAuthenticated) {
            return <button onClick={logout}>Logout</button>;
          } else {
            return (
              <div>
                <button onClick={signup}>Signup</button>
                <button onClick={login}>Login</button>
              </div>
            );
          }
        }}
      </Authenticator>
    </AuthProvider>
  );
}

Firestore

import React from 'react';

import { FirestoreProvider, Collection, Document } from 'react-firestarter';

function Firestore() {
  return (
    <FirestoreProvider firestore={firebase.firestore()}>
      <Collection name="todos">
        {({ isLoading, todos })} => {
          if (isLoading) {
            return <div>Loading</div>;
          } else {
            (
              todos.map(todo => {
                const { id, text } = todo;

                return (
                  <Document key={id} id={id} collection="todos">
                    {({ remove })} => {
                      <div>
                        <span>{text}</span>
                        <span>
                          <button onClick={remove}>X</button>
                        </span>
                      </div>
                    }
                  </Document>
                );
              });
            )
          }
        }
      </Collection>
    </FirestoreProvider>
  );
}

Render Methods and Props

AuthProvider

| Name | Type | Default | Description | | ------------- | :----: | :------: | ------------------------------------------------------------------------------------- | | fireauth | object | required | your own initialized firebase authentication module | | verifyByEmail | bool | true | if true, users will be required to verify their identity through an email upon signup |

Authenticator

| Name | Type | Default | Description | | --------- | :--: | :-----: | ------------------------------------------------ | | onSuccess | func | | callback for successful login or signup | | onError | func | | callback for failed login or signup |

An instantiated Authenticator will receive the following:

| Name | Type | Description | | ------------------ | :--: | -------------------------------------------------------------------------------------------------------- | | isAuthenticated | bool | lets us know if we have an authenticated user | | isAuthenticating | bool | lets us know if a user is in the process of authenticating | | redirectToReferrer | bool | useful for redirecting an authenticated user to original route they landed upon | | getCurrentUser | func | returns our authenticated user | | signup | func | signs a user up; will send a verification email unless verifyByEmail is set to false in AuthProvider; takes two arguments - the first is the user to signup, and the second is a context argument which will be returned to the callback method | | login | func | logs a user in; will not succeed if the user has not and should verify their identity via email; takes two arguments - the first is the user to login, and the second is a context argument which will be returned to the callback method | | logout | func | logs a user out |

FirestoreProvider

| Name | Type | Default | Description | | --------- | :----: | :------: | ---------------------------------------------- | | firestore | object | required | your own initialized firebase firestore module |

Collection

| Name | Type | Default | Description | | -------- | :----: | :------: | ----------------------------------------------------------------------------------------------- | | name | string | required | name of the firestore collection | | onError | func | | callback for successful fetch of collection | | realtime | bool | true | listen for realtime snapshot updates |

An instantiated Collection will receive the following:

| Name | Type | Description | | ------------------ | :---: | --------------------------------------------------------------------------------------------------------------------------------------------- | | isLoading | bool | lets us know if our document collection is in the process of loading | | [collectionName] | array | collection of documents; contains an id and the result of doc.data(); the prop name is the same as the name prop passed into Collection |

Document

| Name | Type | Default | Description | | ---------- | :----: | :------: | ----------------------------------------------------------------------------------------- | | collection | string | required | name of the firestore collection the document belongs to | | id | any | | id of the document; required for all methods except add | | onSuccess | func | | callback for successful execution of add, remove, update | | onError | func | | callback for failed execution of add, remove, update, and non-realtime fetch | | realtime | bool | false | listen for realtime snapshot updates | | fetch | bool | false | get a document or listen for realtime snapshot updates |

An instantiated Document will receive the following:

| Name | Type | Description | | --------- | :----: | ------------------------------------------------------------- | | add | func | adds a document; takes two arguments - the first is the item to add, and the second is a context argument which will be returned to the callback method | | remove | func | removes a document; takes one argument - a context which will be returned to the callback method | | update | func | updates a document; takes two arguments - the first is the date to update, and the second is a context argument which will be returned to the callback method | | doc | object | a single document object; contains the result of doc.data() | | isLoading | bool | lets us know if our document is in the process of loading |

License

MIT © jmpolitzer