定时器


class Blink extends Component {
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {showText: true};

setInterval(()=> {
this.setState(previousState=> {
return {showText: !previousState.showText};
});
}, 100);
}

render() {

let display = this.state.showText ? this.props.text : '';

return (<Text> {display}</Text>);
};
}


export default class App extends Component<{}> {
render() {
return (
<View>
<Blink text='I love to blink'/>
<Blink text='Yes blinking is so great'/>
<Blink text='Why did they ever take this out of HTML'/>
<Blink text='Look at me look at me look at me'/>
</View>
);
}
}
原文地址:https://www.cnblogs.com/zhibin/p/8352022.html