1
在組件中,加載listview和所有內容。React-Native:在加載組件時在後臺運行一個函數
是否可以在後臺運行一個函數來每隔幾分鐘重新載入一次listview數據?
如果有, 當用戶離開組件(轉到另一個選項卡,iOS)時,該功能是否會停止?
在組件中,加載listview和所有內容。React-Native:在加載組件時在後臺運行一個函數
是否可以在後臺運行一個函數來每隔幾分鐘重新載入一次listview數據?
如果有, 當用戶離開組件(轉到另一個選項卡,iOS)時,該功能是否會停止?
您可以通過在componentDidMount中添加setInterval並在componentWillUnmount中將其清除來完成此操作。
let interval;
class HelloWorld extends Component {
componentDidMount() {
interval = setInterval(() => {
// do what you want here.
}, 10000);
}
componentWillUnmount() {
clearInterval(interval);
}
render() {
return (
<Text>Hello world!</Text>
);
}
}