如果我按下按钮代码每5秒执行一次,我就知道了

时间:2017-06-23 10:22:18

标签: react-native

如果我按下按钮代码每5秒执行一次,我就会这样做 在其他语言中,我使用endlis循环 我把内部循环睡眠功能 这是我的代码

_onPress() {
var ws = new WebSocket('ws://myhost.org:800');
ws.onopen = () => {
// connection opened
ws.send("hi)
ws.close();
};
}
render() {
return (
<View style={styles.container}>
<Button
onPress={this._onPress.bind(this)}
title="open"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
</View>
);
}

1 个答案:

答案 0 :(得分:0)

您可以在按钮点击事件中使用setInterval,例如:

setInterval( () => { 
    //your code
}, 1000); // your interval

否则请使用以下其中一项:https://github.com/fractaltech/react-native-timerhttps://github.com/expo/react-native-timer-mixin