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-firebase-image-upload-control

v2.0.0

Published

An image uploader control for Firebase Storage

Downloads

27

Readme

react-firebase-image-upload-control

A image uploader for react that uploads images firebase storage.

react-firebase-image-upload-control in action

Installation

Run yarn add react-firebase-image-upload-control or npm i react-firebase-image-upload-control --save-prod to install the package in your app.

Prerequisites

You will need react, react-dom and firebase installed in your app. They are listed as peer dependencies only for this package, so installing the package will not automatically install those packages in your app.

Make sure you have initialized firebase somewhere in your app using your Firbase project's JSON file, e.g.:

import firebase from "firebase";

const config = {
  apiKey: "<API_KEY>",
  authDomain: "<PROJECT_ID>.firebaseapp.com",
  databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
  storageBucket: "<BUCKET>.appspot.com"
};
const firebaseApp = firebase.initializeApp(config);

You can copy your firebase-config.json file down from your Firebase project. See Google's instructions on how download your config file; (you want the "web app" file). Your project must be enabled for Cloud Storage, in which case it will have the storageBucket property shown in the example above.

You will need to have logged into your Firebase project in your app before attempting to use the control. You check the demo app in this repo to see how I do that.

Example

This is a shortened version of App.js in the /demo folder.

// Example code created with Create React App
import React, {useEffect, useState} from "react";
import {initializeApp} from "firebase/app";
import {
  browserSessionPersistence,
  getAuth,
  setPersistence,
  signInWithEmailAndPassword,
  signOut
} from "firebase/auth";
import "firebase/database";
import "./App.css";

import ReactFirebaseImageUploader from "./.package";
import Login from "./Login";

// You must supply this!
import firebaseConfigObj from "./firebaseconfig/firebase-config.json";
const firebaseApp = initializeApp(firebaseConfigObj);
const auth = getAuth();

const loginProviders = {
  signInWithEmailAndPassword,
  signOut,
  browserSessionPersistence,
  setPersistence
};

const App = () => {
  const [currentUser, setCurrentUser] = useState();
  const [loginDetailsPolled, setLoginDetailsPolled] = useState(false);

  const imageUploaderSharedProps = {
    firebaseApp,
    storageFolder: "rfiu-test"
  };

  useEffect(() => {
    auth.onAuthStateChanged(function (user) {
      if (!loginDetailsPolled) {
        setLoginDetailsPolled(true);
      }
      setCurrentUser(user?.email);
    });
    return () => {};
  }, [loginDetailsPolled]);

  return (
    <div className="App">
      <h1>React Firebase Image Uploader Test</h1>
      {loginDetailsPolled ? (
        <Login {...loginProviders} auth={auth} user={currentUser} />
      ) : (
        "Checking login details..."
      )}
      <div style={{marginTop: 40, marginBottom: 100}}>
        {currentUser ? (
          <>
            <div>
              <h4>Vanilla Example</h4>
              <ReactFirebaseImageUploader
                {...imageUploaderSharedProps}
                multiple
              />
            </div>
          </>
        ) : null}
      </div>
    </div>
  );
};

Props

The main two props you need to pass, as shown in the example above, are firebaseApp and storageFolder.

For the other props available, check the documentation of module & props. These are autogenerated from typescript interfaces. See the FirebaseUploadImageProps interface.

Contributing

You're a Dev and you want implement a fix or add a feature? Read the instructions on how to contribute to the this package.

Changes

Read the change log.

Acknowledges

This package is really just a stitching together of two other projects, react-firebase-file-uploader and react-dropzone.