Coder Social home page Coder Social logo

kayuapi / reactfire Goto Github PK

View Code? Open in Web Editor NEW

This project forked from firebaseextended/reactfire

0.0 1.0 0.0 2.78 MB

Hooks, Context Providers, and Components that make it easy to interact with Firebase.

Home Page: https://firebaseopensource.com/projects/firebaseextended/reactfire/

License: MIT License

JavaScript 0.87% Shell 1.20% TypeScript 96.79% Dockerfile 1.14%

reactfire's Introduction

Reactfire

Hooks, Context Providers, and Components that make it easy to interact with Firebase.

If you're looking for docs for the deprecated ReactFire v1 (the one that uses mixins), click here

Status: Alpha. ReactFire is meant for React Concurrent Mode, which is only available in experimental React builds.

What is ReactFire?

  • Easy realtime updates for your function components - Reactfire's hooks, like useFirestoreCollection and useUser, let you easily subscribe to events, and automatically unsubscribe when your component unmounts.
  • Loading states handled by <Suspense> - Reactfire's hooks throw promises that Suspense can catch. No more isLoaded ?... - let React handle it for you.
  • Dead-simple Real User Monitoring (RUM) - Easily enable Firebase Performance Monitoring's automatic traces, and instrument your Suspenseful loads with Reactfire's <SuspenseWithPerf> component

Install

# npm
npm install --save reactfire

# yarn
yarn add reactfire

Example use

Check out the live version on StackBlitz!

import React, { Component } from 'react';
import { render } from 'react-dom';
import './style.css';
import {
  FirebaseAppProvider,
  useFirestoreDocData,
  SuspenseWithPerf
} from 'reactfire';

import 'firebase/performance';

const firebaseConfig = {
  /* add your config object from the Firebase console */
};

function Burrito() {
  // lazy load the Firestore SDK and create a ref
  const burritoRef = useFirestore()
    .collection('tryreactfire')
    .doc('burrito');

  // subscribe to the doc. just one line!
  // throws a Promise for Suspense to catch,
  // and then streams live updates
  const burrito = useFirestoreDocData(burritoRef);

  // get the value from the doc
  const isYummy = burrito.yummy;

  return <p>The burrito is {isYummy ? 'good' : 'bad'}!</p>;
}

function App() {
  return (
    <FirebaseAppProvider firebaseConfig={firebaseConfig} initPerformance>
      <h1>๐ŸŒฏ</h1>
      <SuspenseWithPerf
        fallback={'loading burrito status...'}
        traceId={'load-burrito-status'}
      >
        <Burrito />
      </SuspenseWithPerf>
    </FirebaseAppProvider>
  );
}

render(<App />, document.getElementById('root'));

Learn More

Contributing

For development

  1. Clone this repository (or a fork)
  2. At the project root, install all modules by running yarn install.
  3. cd into the reactfire directory. Run yarn and yarn watch.
  4. In a new terminal, cd into the reactfire/sample directory. run yarn and yarn start.
  5. Head over to https://localhost:3000 to see the running sample! If you edit the reactfire source, the sample will reload.

Testing

  1. cd into the reactfire/reactfire directory
  2. run yarn test

reactfire's People

Contributors

jhuleatt avatar jamesdaniels avatar firebase-ops avatar davideast avatar mimming avatar nicolasgarnier avatar puf avatar jaylandro avatar insin avatar ramyathulasingam avatar danielmahal avatar timotius02 avatar catrawalkar avatar startupandrew avatar npmcdn-to-unpkg-bot avatar tstirrat avatar shashankanataraj avatar seanemmer avatar prescottprue avatar samtstern avatar raicuparta avatar mjackson avatar llad avatar joeyyang avatar martellaj avatar haroenv avatar cskiwi avatar edi avatar davepwsmith avatar adrw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.