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

postsFetch is undefined #27

Closed
chickencoder opened this issue Dec 29, 2015 · 3 comments
Closed

postsFetch is undefined #27

chickencoder opened this issue Dec 29, 2015 · 3 comments

Comments

@chickencoder
Copy link

Not sure if it's something I'm doing stupidly wrong this evening or something's not right...

In my code I have react-refetch:

import { connect } from 'react-refetch'

I have my component:

export default class PostFeed extends React.Component {
  constructor(props) {
    super(props)
  }

  render() {
    const { postsFetch } = this.props

    if (postsFetch.pending) {
      return <span>Loading Posts...</span>
    } else if (postsFetch.rejected) {
      return <span>Failed to load posts</span>
    } else if (postsFetch.fulfilled) {
      return (
        <Post>
          {postsFetch.value}
          <span>This is a post</span>
        </Post>
      )
    }
  }
}

and I have my refetch connect...

connect((props) => ({
  postsFetch: `https://api.github.com/users/${props.user}/gists`,
}))(PostFeed)

and all I'm getting is that postsFetch is undefined.

Any ideas?

@ryanbrainard
Copy link
Contributor

Try moving export default before connect. As you have it now, you're exporting the unconnected component, so it's undefined.

Closing this now, but reopen if you're still having issues.

@ryanbrainard
Copy link
Contributor

Re-reading the first example in the readme, I can totally see why you did the export like you did. I'm going reopen this as a reminder for myself (or anyone who wants to send a PR) to update it to make it clearer.

@ryanbrainard ryanbrainard reopened this Dec 30, 2015
@chickencoder
Copy link
Author

Oh thank you! Works great 👍

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

2 participants