Skip to content

Commit 4f57d50

Browse files
authored
Provide shouldInvalidatePreviousData prop
Fixes apollographql#2202
1 parent 6f6b6ed commit 4f57d50

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Query.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
9494
static propTypes = {
9595
client: PropTypes.object,
9696
children: PropTypes.func.isRequired,
97+
shouldInvalidatePreviousData: PropTypes.func,
9798
fetchPolicy: PropTypes.string,
9899
notifyOnNetworkStatusChange: PropTypes.bool,
99100
onCompleted: PropTypes.func,
@@ -202,6 +203,10 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
202203
this.queryObservable = null;
203204
this.previousData = {};
204205
this.updateQuery(nextProps);
206+
} else if (typeof nextProps.shouldInvalidatePreviousData === 'function') {
207+
if (nextProps.shouldInvalidatePreviousData(nextProps.variables, this.props.variables)) {
208+
this.previousData = {};
209+
}
205210
}
206211

207212
if (this.props.query !== nextProps.query) {

0 commit comments

Comments
 (0)