javascript - Using shouldComponentUpdate to prevent jitter on rerender
问题描述
I have an issue with my React application when loading the next page of items. Some sections of the page load before others and some sections load with data from the previous page before quickly switching to data from the new one. The functionality works fine, but it looks a bit janky.
I have solved this issue by adding state to determine whether the component is loading the next page, and only updating it when it isn't loading.
async nextPage(){
this.setState({isLoading: true})
await apiCall()
this.setState({isLoading: false})
}
shouldComponentUpdate(nextProps, nextState, nextContext) {
return !this.state.isLoading
}
This seems like bad practice and something that could cause unrelated consequences. Is there a cleaner solution for this issue?
解决方案
推荐阅读
- java - 如何在 SPRING REST API 中使用 SQL 查询处理“ALL”?
- python - matplotlib 以两种不同的方式打印图像
- cordova - 如何编辑 config.xml 以在 phonegap 构建中启用 android 调试?
- javascript - 为什么数字从 Object.prototype 继承时不是 Object 的实例?
- mysql - 错误消息:无法连接到数据库服务器
- javascript - 在 AngularJS 应用程序上使用 google API then() 函数
- java - 为什么每次调用 SpringMVC 服务中的简单方法都比静态方法慢?
- java - 在每次仪器测试之前重置/清除应用程序 (Android Studio)
- vue.js - 如何将表单数据从父组件传递给子组件?
- apache - 你能帮我删除重写规则中的 index.php 吗?