react-firebase-context icon indicating copy to clipboard operation
react-firebase-context copied to clipboard

without decorators

Open jim-obrien-orig opened this issue 6 years ago • 4 comments

Howdy, Thanks for the library - it's very useful. It would be more useful, though, if it didn't have decorators, because getting them to work is a pain.

I ended up pulling out the hoc - withFirestore and using auto-bind as follows:

import React, { Component } from 'react'
import autoBind from 'auto-bind'
import { FirestoreContext } from 'react-firebase-context'

const withFirestore = WrappedComponent => {
  return class extends Component {
    constructor(props) {
      super(props)
      autoBind.react(this)
    }
    render() {
      return (
        <FirestoreContext.Consumer>
          {({ firestore, data, query }) => {
            firestore.data = data
            firestore.query = query
            return <WrappedComponent firestore={firestore} {...this.props} />
          }}
        </FirestoreContext.Consumer>
      )
    }
  }
}

export default withFirestore

and then using it as follows:

export default withFirestore(MyClass)

jim-obrien-orig avatar Feb 20 '19 03:02 jim-obrien-orig

Hey, thanks for taking the effort submitting the issue and the PR :+1:

I'm not sure if I'm following though, can you send more details on what error you're getting? As far as I can see there shouldn't be anything needing the bind in the HOC (and decorator usage is 100% optional), but very possible I'm just missing something here :blush:

julianburr avatar Feb 23 '19 06:02 julianburr

Hi Julian, I could e wrong - like I said, I'm newer to the react/es6 framework. I remember trying using the firestore as a plain hoc without the decorator in create-react-app and having an error. I'll try it again on monday.

jim-obrien-orig avatar Feb 23 '19 20:02 jim-obrien-orig

Yeah, not saying you're wrong, very possible that there is an issue. If you could post the error message you're getting would be really helpful :blush:

julianburr avatar Feb 24 '19 10:02 julianburr

Hey Julian, from what I read, I can say this is a suggestion to make the library easier to use and it is 'not' a bug or issue report. So there is no error as well. Jim is suggesting you a solution that removes the urge of using decorators. @jim-obrien-orig correct me please if I am wrong.

metacoding avatar Mar 20 '20 22:03 metacoding