Code Monkey home page Code Monkey logo

reactfire's Introduction

ReactFire

All Contributors

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

โš ๏ธ Status: Experimental. The API is intended to be stable, but 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 - Hooks like useUserand useFirestoreCollection let you easily subscribe to auth state, realtime data, and all other Firebase SDK events. Plus, they 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.
  • Faster initial page load times - Load only the code you need, when you need it, with useFirestore, useAuth, useRemoteConfig, and more.
  • Convenient components for common use cases - Only want to render a component if a user is signed in? Wrap it in <AuthCheck />. Need to automatically instrument your Suspense load times with RUM? Use <SuspenseWithPef />.

Install

# npm
npm install --save reactfire firebase

# or

# yarn
yarn add reactfire firebase

Depending on your targeted platforms you may need to install polyfills. The most commonly needed will be globalThis and Proxy.

Docs

Example use

Check out the live version on StackBlitz!

import React, { Component } from 'react';
import { createRoot } from 'react-dom';
import { FirebaseAppProvider, useFirestoreDocData, useFirestore, SuspenseWithPerf } from 'reactfire';

const firebaseConfig = {
  /* Add your config 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);

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

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

// Enable Concurrent Mode
// https://reactjs.org/docs/concurrent-mode-adoption.html#enabling-concurrent-mode
createRoot(document.getElementById('root')).render(<App />);

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

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


w3bdesign

๐Ÿ’ป

Scott Prue

๐Ÿ’ป

Jeff

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

reactfire's People

Contributors

jhuleatt avatar jamesdaniels avatar davideast avatar firebase-ops avatar mimming avatar nicolasgarnier avatar puf avatar jaylandro avatar insin avatar ramyathulasingam avatar allcontributors[bot] avatar danielmahal avatar timotius02 avatar shelcindra avatar catrawalkar avatar startupandrew avatar npmcdn-to-unpkg-bot avatar dependabot[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

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.