3

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.

cheesus
  • 11,077
  • 10
  • 64
  • 122
  • 1
    It adds the functionality listed in its README. The point is explicitly to *not* do everything manually--which of course you could do. – Dave Newton Aug 23 '19 at 19:42
  • 1
    @DaveNewton That's exactly my question: what am I doing manually that the library can do for me? The README says for example "Out of the box support for authentication". But `react-native-firebase` can do that with one line: `firebase.auth().signInWithEmailAndPassword(...)`. I don't see why this is more manual work than http://docs.react-redux-firebase.com/history/v3.0.0/docs/auth.html – cheesus Aug 23 '19 at 19:56
  • Dunno; can't see your code. Your snippet creates a user; the auth docs for r-r-f show more functionality than creating a user. Whether or not it's more or less work than what you're doing now is impossible to guess. – Dave Newton Aug 23 '19 at 20:01
  • @DaveNewton I don't have any code yet, I'm just trying to find out for what I need which library. Do you know of an example where it's clearly visible that r-r-f saves manual work? Like, one "manual" example, and then the same with r-r-f? – cheesus Aug 23 '19 at 20:04
  • I'm not sure what you're asking for. Whether or not it saves manual labor depends, explicitly, on what you're doing. You would be better served by looking at the front-page explanations of what it does, and potentially several of the examples, based on what you think you want to do. – Dave Newton Aug 23 '19 at 20:07
  • @DaveNewton You said its point was to not do everything manually. I was hoping for an example backing that claim. The online examples don't seem to be very enlightening. [Getting Started](http://docs.react-redux-firebase.com/history/v3.0.0/docs/getting_started.html) is just two pages of code without any explanation. – cheesus Aug 23 '19 at 20:25
  • @DaveNewton Never mind, I've got my anwer. Thanks for your comments. – cheesus Aug 23 '19 at 20:27
  • Again--it's not clear what you actually want. They have HOCs that wrap up listening without manual work. Their connect makes DB access transparent. It makes pulling in the DB you're working with (along with auth/auth) essentially invisible to mainline code. All of this is on the front page of the repo. – Dave Newton Aug 23 '19 at 20:36
  • @DaveNewton Now I understand more clearly what the Getting Started page wants to tell. Maybe the language is a bit terse. Maybe I would have understood it if my knowledge of the technologies involved was a bit better. If you google "Why do I need Redux?", you find a lot of explanations that show how one works without Redux, and then shows the problems that Redux solves. I was looking for something like that. – cheesus Aug 23 '19 at 20:51
  • 1
    Understood, it just seems (to me) like the repo home answers those questions. You're unlikely to find as many resources for "auxiliary" libraries as for "core" libraries, because once you're outside "core" tech, there are an essentially unlimited number of options. – Dave Newton Aug 23 '19 at 20:53

1 Answers1

2

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

cutiko
  • 7,465
  • 3
  • 38
  • 48
  • Does it update the `connect` function so that it automatically listens to changes in the database? And does it automatically store the redux state in Firebase? – cheesus Aug 23 '19 at 20:00
  • 1
    Yes! Changing data to the firebase-redux will change your data on the online database. Then every component listening to that firebase-redux state will be updated up to the UI level. It basically reflects the online database structure and allows you to modify it directly. – cutiko Aug 23 '19 at 20:22