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

Pagination #3

Closed
alex-mcleod opened this issue Jun 6, 2016 · 2 comments
Closed

Pagination #3

alex-mcleod opened this issue Jun 6, 2016 · 2 comments

Comments

@alex-mcleod
Copy link

Hello, thanks for providing this. How would I go about paginating data correctly?

@r0b1n
Copy link
Owner

r0b1n commented Jun 6, 2016

Hi @alex-mcleod
With Relay we can use this approach for pagination https://facebook.github.io/relay/graphql/connections.htm

Please see example by Facebook.

// NewsFeed.react.js
class NewsFeed extends React.Component {
  render() { ... }

  loadMore() {
    // read current params
    var count = this.props.relay.variables.count;
    // update params
    this.props.relay.setVariables({
      count: count + 5,
    });
  }
}

Also I think it is possible to pass variables to Actions. Not sure but you may need to set page variable in initialVariables to null and add some logic in prepareVariables.

// on page one (for example with articles):
<Button onPress={() => Actions.Comments({id: 123, page: 1})}> // page: 1 not needed if there is additional logic in prepareVariables which manage default value.
  See comments
</Button>
// on page two, with comments
Actions.Commend
<Button onPress={() => Actions.refresh({page: 2})}>
  Go to page 2
</Button>

P.S. Backend from this example doesn't support pagination. So make sure your backend does.

@alex-mcleod
Copy link
Author

@r0b1n excellent, thanks for the example. It turned out I need to add a 'viewer' field to my root level query, due to this issue ---> facebook/relay#112. After doing that, I was able to paginate using variables in my react container, rather than using the refresh action to update page state. The problem with refreshing was it would remount the component each time.

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