javascript - 无限滚动 React JS 回收 dom
问题描述
我完成了对我的组件的无限滚动流程。
一切都按预期工作。我想为此添加一个回收功能,当您向下滚动时,DOM 元素也会从顶部删除。然后在您向上滚动时添加回来。
一段时间以来,我一直在使用不同的方法。在我的情况下,您可以一次获取所有数据(52,000 条)记录,然后在查看方法中添加或删除它。但我希望它也能在获取限制的情况下工作。
因此,当您向 DOM 降低添加元素时获取数据,当您降低时它会从顶部删除它们,当您升高时它们会被添加回来。我不知所措。下面是组件的代码。以及它现在如何工作的 GIF。
var React = require('react');
import allTheStuffToMakeMyComponentWork = require'../alltheStuff.js'
class ClassInstancesListView extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
classInstancesArr: [],
classInstanceStatusFilterStr: 'incomplete',
limit: 25,
search: '',
scrolling: false
};
}
componentDidMount() {
//fetchTheData
onClassInstancesStoreChange()
}
componentWillUnmount() {
//destroying listeners
}
componentDidUpdate(prevProps, prevState, snapshot) {
//adding the event listener once there is stuff fetched and on the dom
}
onClassInstancesStoreChange = (opInfo) => {
//getting all my data
};
changeFilterStrAndRefetch = (filterStr) => {
//changing drop down for filtering result
};
renderClassInstancePipelines() {
//mapping through fetchewd data and rendering on cards
}
updateSearch(event) {
//Event handler for using the search by type functionality.
}
loadMore = () => {
//Will be called only when the scroll event reaches the bottom of the page.
};
handleScroll = (e) => {
//Scroll Listener which is initiatied on mount and listens for when the scroll reaches the last element in the #pipeLines list.
};
render() {
return(
//calling the function to render my stuff
)
}
module.exports = ClassInstancesListView;
解决方案
推荐阅读
- go - 鸭子打字:如何在go中隐式转换从一个接口到另一个接口
- javascript - 检查在 jQuery Bootstrap 多选中单击了哪个 optgroup
- javascript - 将数据从包含插槽内容的组件传递到该插槽内容组件
- kotlin - 在 LiveData 或 MutableLiveData 中包装 MutableList
- javascript - 如何编辑/更新数组中的对象并保留所有其他嵌套数据?
- vb.net - 无法回调变量
- css-selectors - 在 Slick Carousel 中定位活动元素
- java - Tomcat 在关闭时是否会过早破坏 ServletContext?
- python-3.x - 类型提示实现两个接口的对象
- docker - phpMyAdmin - Docker容器上的错误“调用成员函数getPath on null”