Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

without decorators #1

Open
jim-obrien-orig opened this issue Feb 20, 2019 · 4 comments
Open

without decorators #1

jim-obrien-orig opened this issue Feb 20, 2019 · 4 comments

Comments

@jim-obrien-orig
Copy link

jim-obrien-orig commented Feb 20, 2019

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)
@julianburr
Copy link
Owner

Hey, thanks for taking the effort submitting the issue and the PR 👍

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 😊

@jim-obrien-orig
Copy link
Author

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.

@julianburr
Copy link
Owner

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 😊

@metacoding
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants