我的容器是一个滚动视图,里面是一个平面列表,它从服务器加载数据。
平面列表:
<VirtualizedList
ListEmptyComponent={<NoData />}
data={data}
getItem={(items, index) => items.get(index)}
getItemCount={(items) => items.size}
keyExtractor={(item, index) => String(index)}
renderItem={this._renderItem}
refreshControl={
<RefreshControl
refreshing={loading}
onRefresh={this._onRefresh.bind(this)}
/>
}
onEndReached={this.handleLoadMore}
onEndReachedThreshold={0.1}
onMomentumScrollBegin={() => {
Log('onMomentumScrollBegin fired!')
this.onEndReachedCalledDuringMomentum = false;
}}
/>
Run Code Online (Sandbox Code Playgroud)
这handleLoadMore是:
handleLoadMore = () => {
Log('handleLoadMore fired!');
if (!this.onEndReachedCalledDuringMomentum) {
// fetch data..
this.onEndReachedCalledDuringMomentum = true;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是handleLoadMore从未被调用和onMomentumScrollBegin也从未被调用。
怎么解决这个问题呢?
这是代码:
import React, { useState } from 'react'
function App() {
const [a, setA] = useState(1)
setA(2)
return (
<div>
<h1>{a}</h1>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
错误。重新渲染次数过多。React 限制渲染数量以防止无限循环。
为什么会导致无限循环呢?
我认为原因是函数组件只是作为渲染函数setState,因此在函数中会导致无限循环render。
有官方解释吗?
在iOS系统应用程序时钟中,当我启动计时器或秒表,退出应用程序,终止并重新打开它时,计时器或秒表仍在运行.
我如何timer在后台运行?
Apple是如何做到的?