0
私のOnEnterコールバックで、より多くのデータを取得するためにAPI呼び出しを行っています。フェッチされたデータは、私が持っている要素の配列に追加されます。バックアップをスクロールすると、コンポーネントがビューポートに戻ったときにAPIコールが再度トリガされます。ウェイポイントに反応する最初の時間の後にsupressを呼び出す
これを回避する方法はありますか?
コードサンプル: さて、私は少しそれをクリーンアップしてみましょう:@jmeas
fetchData(props){ function to call the api with server side pagination
if(props.previousPosition != 'above') { //an attempt to check if we passed that waypoint, do not call the api again
this.setState({page: this.state.page + 1}, function() { //increment the page number
this.getCatalogItems(this.state.categoryId, this.state.page) //make api call with incremented page number
.then((res) => {
console.log("fetched more data with scroll", res) //results
})
})
}else{
console.log("not calling fetch data")
}
}
これは、私はウェイポイントを呼び出しています方法です:
class ProductContainer extends React.Component {
constructor(props) {
super(props);
console.log("catalog product container initialized", this.props);
}
render() {
const {catalogProducts, getCatalogItems, renderWaypoint} = this.props;
console.log("props in roduct container", this.props)
return (
<div className="products-container">
{
catalogProducts && catalogProducts['products'] ?
catalogProducts['products'].map((product) => {
return (
<span>
HIIIIIIIIIIIIIIIIIIIIIIIIIII
<CatalogProduct product={product}/>
</span>
)
})
:
false
}
{renderWaypoint()}
########################################################################### way point here ################################################
</div>
);
}
}
ProductContainer.propTypes = {
catalogProducts: React.PropTypes.any.isRequired,
getCatalogItems: React.PropTypes.func.isRequired,
renderWaypoint: React.PropTypes.func.isRequired
};
export default ProductContainer;
何私はしたい:
私は無限を持っているスクロールカタログページ。最初のAPIコールから返された商品をレンダリングした後、もう一度サーバーにラウンドトリップしてレンダリングしたいウェイポイントまでスクロールしたときに、apiコールを行いたいです。
これは、私がデータをフェッチする必要があるpageNumberを渡すのと同じapi呼び出しです。私はAPI呼び出しをしている間に、ページ番号をインクリメントするだけです –
例としてコードがありますか? –
私はあなたが何を言っているのか理解していれば、あなたのロード機能にページ番号を渡していると思います...おそらく私の更新されたコードブロックは役に立ちますか? –