Search code examples
firebasereact-nativereduxreact-redux-firebase

What problem does `react-redux-firebase` solve?


I'm new to all of these technologies, but as far as I understand it, you can use React Native with Redux and Firebase without react-redux-firebase. You could just use

  • react
  • react-native
  • redux
  • react-redux
  • react-native-firebase

Then you load data from Firebase (e.g. Firestore) and put the data in a reducer so it gets merged into the redux store.

Why do I need react-redux-firebase? What problem does it solve?

I have tried its docs, but they seem to be written for someone who is already familiar with its goals. They do not really explain, and when reading the examples, I do not understand why I specifically need react-redux-firebase instead of the setup listed above.


Solution

  • Firebase is on your state, listen to it an modify it, it will change your Firebase database. After the data on the database is changed the components listening will change as well.

    This will create an item in the database

        updateTodo: props => () => {
          return firebase.update(`todos/${params.todoId}`, { done: !todo.isDone })
        }
    

    So any component listening to that node will get updated:

      connect((state) => ({
        todos: state.firebase.data.todos,
        // profile: state.firebase.profile // load profile
      }))
    

    It solves the problem of having multiple sources of truth, your Firebase database is your only source of truth, otherwise, you change your local data and then you update the data online and then if it works nothing else but if it fails you have to update the local data again