0
我有以下apollo-graphql客戶端代碼,其中我每30秒觸發一次graphql查詢並獲取數據。Apollo Graphql:避免在重新讀取期間加載指標
import React, { Component } from 'react';
import { gql, graphql } from 'react-apollo';
import _ from 'underscore';
class Test extends Component {
render() {
if (this.props.TestData.loading) {
return <div>Loading...</div>
}
if (this.props.TestData.error && this.props.TestData.error !== null) {
return <div>Error...</div>
}
// Iterate through the this.props.TestData.getTestData and build the Table of data here
return (
<table>
_.map(this.props.TestData.getTestData.testList, (test) => {
<tr>
<td>{test.testName}</td>
<td>{test.status}</td>
</tr>
})
</table>
);
}
}
const TestQuery = gql`
query TestQuery() {
getTestData() {
testList {
testName
status
}
}
}
`;
const options =() => ({
pollInterval: 30000,
});
const withTestData = graphql(TestQuery, {
name: 'TestData',
options,
});
export default withTestData(Test);
我所面臨的問題是,每30秒後,我看到Loading...
因爲查詢重新觸發。我希望Loading...
僅在頁面啓動時才顯示,此後它應該是平滑更新,我不想向用戶顯示Loading...
指示器。不知道如何實現這一點。
太棒了,它工作。編輯您的代碼,因爲有一個否定缺失並修改爲指向正確的字段。 –