Skip to content

Commit fe5e57a

Browse files
Merge pull request #37 from Floriferous/patch-1
Provide shouldRefetch option to prevent refetching of static queries
2 parents 29158cd + 83b7601 commit fe5e57a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ const query = createQuery('usersWithEmails', {
9090
<td>
9191
For static (`reactive = false`) queries only, sets `isLoading` to true every time you call refetch until the data is loaded. Set this to false to only get `isLoading` on the initial fetch.
9292
</td>
93+
</tr>
94+
<tr>
95+
<td>shouldRefetch</td>
96+
<td>(currentProps, nextProps) => Boolean</td>
97+
<td>`undefined`</td>
98+
<td>
99+
For static queries only, provides a hook into `componentWillReceiveProps` to determine whether the query should be refetched or not. The function will be called with nextProps and currentProps as arguments.
100+
</td>
93101
</tr>
94102
</table>
95103

Diff for: lib/checkOptions.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function(options) {
1010
loadingComponent: Match.Maybe(Match.Any),
1111
dataProp: Match.Maybe(String),
1212
loadOnRefetch: Match.Maybe(Boolean),
13+
shouldRefetch: Match.Maybe(Function),
1314
});
1415

1516
if (options.reactive && options.poll) {

Diff for: lib/withStaticQuery.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ export default function withStaticQueryContainer(config) {
1616

1717
componentWillReceiveProps(nextProps) {
1818
const { query } = nextProps;
19-
this.fetch(query);
19+
20+
if (!config.shouldRefetch) {
21+
this.fetch(query);
22+
} else if (config.shouldRefetch(this.props, nextProps)) {
23+
this.fetch(query);
24+
}
2025
}
2126

2227
componentDidMount() {

0 commit comments

Comments
 (0)