• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    JavaScript
  • Created over 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React bindings for Firebase

React Firebase

React bindings for Firebase.

⚠️ React Firebase in not maintained anymore

There might come a replacement from React itself with Suspense, but when is not certain. If you want to contribute or maintain this project, send a message to @einarlove.

Installation

npm install --save react-firebase

React Firebase requires React 0.14 and Firebase 3 or later.

Example

import React from 'react'
import firebase from 'firebase'
import { connect } from 'react-firebase'

firebase.initializeApp({
  databaseURL: 'https://react-firebase-sandbox.firebaseio.com'
})

const Counter = ({ value, setValue }) => (
  <div>
    <button onClick={() => setValue(value - 1)}>-</button>
    <span>{value}</span>
    <button onClick={() => setValue(value + 1)}>+</button>
  </div>
)

export default connect((props, ref) => ({
  value: 'counterValue',
  setValue: value => ref('counterValue').set(value)
}))(Counter)

Test for yourself on Codepen.io

Usage

connect([mapFirebaseToProps], [mergeProps])

Connects a React component to a Firebase App reference.

It does not modify the component class passed to it. Instead, it returns a new, connected component class, for you to use.

Arguments

  • [mapFirebaseToProps(props, ref, firebaseApp): subscriptions] (Object or Function): Its result, or the argument itself must be a plain object. Each value must either be a path to a location in your database, a query object or a function. If you omit it, the default implementation just passes firebaseApp as a prop to your component.

  • [mergeProps(ownProps, firebaseProps): props] (Function): If specified, it is passed the parent props and current subscription state merged with the result of mapFirebaseToProps(). The plain object you return from it will be passed as props to the wrapped component. If you omit it, Object.assign({}, ownProps, firebaseProps) is used by default.

Returns

A React component class that passes subscriptions and actions as props to your component according to the specified options.

Note: "actions" are any function values returned by mapFirebaseToProps() which are typically used to modify data in Firebase.

Static Properties
  • WrappedComponent (Component): The original component class passed to connect().
Pass todos as a prop

Note: The value of todos is the path to your data in Firebase. This is equivalent to firebase.database().ref('todo').

const mapFirebaseToProps = {
  todos: 'todos'
}

export default connect(mapFirebaseToProps)(TodoApp)
Pass todos and a function that adds a new todo (addTodo) as props
const mapFirebaseToProps = (props, ref) => ({
  todos: 'todos',
  addTodo: todo => ref('todos').push(todo)
})

export default connect(mapFirebaseToProps)(TodoApp)
Pass todos, completedTodos, a function that completes a todo (completeTodo) and one that logs in as props
const mapFirebaseToProps = (props, ref, firebase) => ({
  todos: 'todos',
  completedTodos: {
    path: 'todos',
    orderByChild: 'completed',
    equalTo: true
  },
  completeTodo = id => ref(`todos/${id}/completed`).set(true),
  login: (email, password) => firebase.auth().signInWithEmailAndPassword(email, password)
})

export default connect(mapFirebaseToProps)(TodoApp)

<Provider firebaseApp>

By default connect() will use the default Firebase App. If you have multiple Firebase App references in your application you may use this to specify the Firebase App reference available to connect() calls in the component hierarchy below.

If you really need to, you can manually pass firebaseApp as a prop to every connect()ed component, but we only recommend to do this for stubbing firebaseApp in unit tests, or in non-fully-React codebases. Normally, you should just use <Provider>.

Props

  • firebaseApp (App): A Firebase App reference.
  • children (ReactElement): The root of your component hierarchy.

Example

import { Provider } from 'react-firebase'
import { initializeApp } from 'firebase'

const firebaseApp = initializeApp({
  databaseURL: 'https://my-firebase.firebaseio.com'
})

ReactDOM.render(
  <Provider firebaseApp={firebaseApp}>
    <MyRootComponent />
  </Provider>,
  rootEl
)

License

MIT

Acknowledgements

react-redux which this library is heavily inspired by.

More Repositories

1

webpack-serve

Takes your webpack config and creates a development server with hot module reloading and error overlay
JavaScript
176
star
2

heroku-buildpack-pnpm

Run PNPM install on Heroku
Shell
38
star
3

spriter

CSS sprite sheet generator
JavaScript
16
star
4

dev-server

Webpack development server
JavaScript
12
star
5

browserify-hogan

Browserify transform plugin for Hogan.js templates
JavaScript
8
star
6

grunt-git-revision

JavaScript
5
star
7

whack-a-mole

Demo for React + Firebase
JavaScript
4
star
8

reactive

React client/server example
JavaScript
4
star
9

react-in-the-responsive-world

Responsive images in React
JavaScript
3
star
10

browserify-ejs

Browserify transform plugin for EJS templates
JavaScript
3
star
11

norwegian-utils

Some functions to handle Norwegian phone numbers etc.
TypeScript
3
star
12

jquery.taplizer

JavaScript
2
star
13

CacheSize

"Caching" images locally for better performance on animating scaled images.
JavaScript
2
star
14

istanbul-instrument-loader

Istanbul Instrument Loader for Webpack
JavaScript
2
star
15

gulpfile-install

[Unmaintained] Gulpfile-install is a command line application that scans your gulpfile.js and install all dependencies.
JavaScript
2
star
16

The-Chase

Simple websocket experiment with iPhone controllers
JavaScript
2
star
17

react-redux-firebase

React bindings for Firebase with Redux
JavaScript
1
star
18

flummox-todo

A minimalist flummox todo list example.
JavaScript
1
star
19

legacy

Legacy browser style sheet generator
JavaScript
1
star
20

Howl

Flash audio bridge
ActionScript
1
star
21

behind

Behind
JavaScript
1
star
22

slide-layout-engine

Simple slide layout manager
JavaScript
1
star
23

vae_local

Vae Platform Local Development Environment
Ruby
1
star
24

Husky

JavaScript
1
star
25

retina

CSS processor which adds retina declarations where retina version images are found, generates scaled down non-retina images and updates the existing stylesheet
JavaScript
1
star
26

transit

Declarative state and physics based transitions in React
JavaScript
1
star
27

denon-firebase

Firebase + Denon Amplifier
JavaScript
1
star
28

jQuery-Transition

Hardware accelerated jQuery transitions
JavaScript
1
star
29

jquery.tapClick

This plugin should solve your unresponsive slow taps.
JavaScript
1
star
30

livewatch

Watches for filesystem changes, runs build systems, and sends updates to LiveReload compatible clients
JavaScript
1
star
31

react-firebase-full-circle

JavaScript
1
star