定时器


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>
);
}
}
posted @ 2018-01-25 16:49  銱ル╬鎯噹  阅读(150)  评论(0编辑  收藏  举报