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); |
Thank You So Much It Helped Me A Lot In My Project :)
can u please share your setup?
in my case thepreviousResult
return the same data as infetchMoreResult
, in other words, the previous results aren't stored.
i have same problem, did you find solution and what was causing this problem? @m1m6
can u please share your setup?
in my case thepreviousResult
return the same data as infetchMoreResult
, in other words, the previous results aren't stored.i have same problem, did you find solution and what was causing this problem? @m1m6
Check your fetch-policy configurations
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can u please share your setup?
in my case the
previousResult
return the same data as infetchMoreResult
, in other words, the previous results aren't stored.