Last active
November 9, 2024 13:13
-
-
Save kkemple/bececb840c99b47a2e25f8086f15f056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { graphql } from 'react-apollo'; | |
import { gql } from 'graphql-tools'; | |
const QUERY = gql` | |
query MatchesByDate($date: Int) { | |
matches(date: $date) { | |
id | |
minute | |
period | |
highlights { | |
... | |
} | |
... | |
} | |
} | |
`; | |
class MatchList extends Component { | |
render() { | |
const ({ data: { loading, errors, matches } }) = this.props; | |
return ( | |
<div className="matchlist"> | |
{loading && <div className="loader" />} | |
{errors && <div className="errors">...</div>} | |
{!loading && !matches && <span className="none">No Matches Found!</span>} | |
{!loading && | |
matches && | |
matches.map(match => <div className="match">...</div>)} | |
{!loading && | |
matches && | |
<button onClick={this.onFetchMore}> | |
Fetch More Matches | |
</button>} | |
</div> | |
); | |
} | |
onFetchMore = () => { | |
const ({ data: { matches, fetchMore } }) = this.props; | |
fetchMore({ | |
variables: { date: matches[matches.length - 1].date }, | |
updateQuery: (previousResult, { fetchMoreResult, queryVariables }) => { | |
return { | |
...previousResult, | |
// Add the new matches data to the end of the old matches data. | |
matches: [ | |
...previousResult.matches, | |
...fetchMoreResult.matches, | |
], | |
}; | |
}, | |
}); | |
} | |
} | |
export default graphql(QUERY)(MatchList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check your fetch-policy configurations