[英]React-Native: run a function in background while component is loaded
在组件中,同时加载了listview和所有内容。
是否可以在后台运行函数以每隔几分钟重新加载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>
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.