React-redux-firebase: question(integrations): how to get firebase instance in v3.*.* since getFirebase() is deprecated

Created on 5 Jan 2019  路  7Comments  路  Source: prescottprue/react-redux-firebase

Since the change to the React context providers (more precisely: https://github.com/prescottprue/react-redux-firebase/pull/566) the getFirebase() is not available anymore. But how do we access our firebase instance from Redux store now, for example from inside of an action creator?

discussion examples question

All 7 comments

(See discussion on Gitter.)

@yorickreum I have been sticking to passing the instance from props.firebase. The current plan is to go expose a middleware and actionCreators so that you can just dispatch the action creators directly with your data. Since it isn't finished yet, I haven't written docs about it yet, but we can discuss more on Gitter. Interested to hear your thoughts!

Sounds good!

Exposing a middleware for thunk would be the same approach as getFirebase() was?

In my particular case I wanted to sign up and send a verification mail directly afterwards. Because I didn't see an actionCreator for sending a verification mail I started to write an own actionCreator, but saw no possibility to access our getFirebase instance... Passing it from the props could be a workaround.

The goal for the middleware is for it to be even more simple than the getFirebase + thunk approach and expose sync action creators for everything instead of wrapped async methods.

All of that aside, auth is exposed so you can call all of the methods directly. The methods that are exposed are wrapped in dispatch since most of them update state, since you don't necessarily need a state update, you can just do a handler similar to in the material example:

import { compose } from 'redux'
import { withHandlers } from 'recompose'
import { withFirebase } from 'react-redux-firebase'

const enhance = compose(
  withFirebase
  withHandlers(
    signupAndEmail: (props) => creds =>
      props.firebase
        .createUser(creds, {
          email: creds.email,
          username: creds.username
        })
        .then(props.firebase.auth().currentUser.sendEmailVerification)
        .then(() => {
          console.log("Signup and email verification successful:")
        })
        .catch(err => {
          console.error("error with signup:", err)
        })
  )
)

any update on this? I want to still have access to firebase instance but use firestoreConnect which I cannot because I use react-redux v6

@idanlo The version of react-redux-firebase available on the next branch has support for react-redux v6 as mentioned in the installation section of the README. That said, I think there is still an open question of the best way to access the instance within separate actions/middlewares/flows such as thunks/sagas or redux-observable.

Directing #617 here as well since I believe it is a similar question.

For now, I personally have been accessing the instance from props and passing it as necessary (even to separate sagas/thunks if necessary instead of having it passed as part of setup).

This is also a duplicate of #635, so going to close this and make future updates there. Thanks to everyone for reaching out with thoughts!

Was this page helpful?
0 / 5 - 0 ratings