Javascript React Native:在加载组件时在后台运行函数
在组件中,同时加载listview和所有内容 是否可以在后台运行函数,每隔几分钟重新加载listview数据 如果是,Javascript React Native:在加载组件时在后台运行函数,javascript,react-native,backgroundworker,web-worker,Javascript,React Native,Backgroundworker,Web Worker,在组件中,同时加载listview和所有内容 是否可以在后台运行函数,每隔几分钟重新加载listview数据 如果是, 当用户离开组件(转到另一个选项卡,iOS)时,功能是否会停止?您可以通过在componentDidMount中添加一个setInterval并在componentWillUnmount中清除它来完成此操作 let interval; class HelloWorld extends Component { componentDidMount() { interva
当用户离开组件(转到另一个选项卡,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>
);
}
}
let间隔;
类HelloWorld扩展组件{
componentDidMount(){
间隔=设置间隔(()=>{
//在这里做你想做的。
}, 10000);
}
组件将卸载(){
间隔时间;
}
render(){
返回(
你好,世界!
);
}
}