5

Background: I have started using react-native-firebase with react-native to integrate with Cloud Firestore. I'm going to start bringing redux into my test application.

Question - Is react-native-firebase ok to continue with as my choice of libraries here? (versus migrating to react-redux-firebase)

Is there an easy way to sum up the difference between the two libraries re when you would you one versus the other? I note with react-native-firebase the installation is quite involved for IOS and Android, so I'm not sure whether react-redux-firebase makes this easier, but if it does do you lose anything in mix?

Greg
  • 34,042
  • 79
  • 253
  • 454

2 Answers2

10

Main difference:

  • react-redux-firebase - for using Firebase with Redux
  • react-native-firebase - for using Firebase JS API with react-native

react-redux-firebase actually supports using react-native-firebase. react-native-firebase provides the Firebase JS API while using native-modules under the hood, meaning you can provide that as your Firebase instance to react-redux-firebase like so:

import { compose, createStore } from 'redux';
import RNFirebase from 'react-native-firebase';
import { getFirebase, reactReduxFirebase } from 'react-redux-firebase';
import thunk from 'redux-thunk';
import makeRootReducer from './reducers';

const reactNativeFirebaseConfig = {
  debug: true
};

const reduxFirebaseConfig = {
  userProfile: 'users', // save users profiles to 'users' collection
};

export default (initialState = { firebase: {} }) => {
  // initialize firebase
  const firebase = RNFirebase.initializeApp(reactNativeFirebaseConfig);

  const store = createStore(
    makeRootReducer(),
    initialState,
    compose(
      reactReduxFirebase(firebase, reduxFirebaseConfig), // pass initialized react-native-firebase app instance
     // applyMiddleware can be placed here
    )
  );

  return store;
};

This setup and more is covered in the react-native recipes section of the docs.

Disclaimer: I am one of the authors of react-redux-firebase

Scott
  • 1,575
  • 13
  • 17
  • thanks for the reply and clearing some things up. Separate to this I don't suppose you would know whether either of the two libraries would handle firebase exceptions differently. I just raised one issue I'm having here: https://github.com/invertase/react-native-firebase/issues/727 – Greg Jan 06 '18 at 23:27
  • Looks like the error has to due with rules not allowing the action that you are performing. Did you confirm that your rules allow you to do what you are doing? Including subcollections? Also, you may have already seen it, but [react-redux-firebase](http://react-redux-firebase.com/docs/firestore.html) supports using Firestore. – Scott Jan 06 '18 at 23:49
1

react-redux-firebase is helper library for firebase. I recommended using both react-native-firebase and react-redux-firebase.

react-native-firebase is easy to write, easy to read, easy to understand. You don't need react-redux-firebase for the small application.

react-native-firebase is awesome.

If you are familiar with firebase, You can use react-native-firebase in 10 minutes.

For example

import Firebase from "react-native-firebase"

....

<Button title="button" onPress={Firebase.analytics().logEvent("pressed")} />
sonicmario
  • 601
  • 8
  • 22