constructor()構造函數和setInterval()定時器

import React, { Component } from ‘react’;
import { AppRegistry, Text, View } from ‘react-native’;

class Blink extends Component {
//構造函數
constructor(props) {
super(props);
this.state = { showText: true };

// 定時器毫秒
setInterval(() => {
  this.setState({ showText: !this.state.showText });
}, 1000);

}

render() {
// 根據當前showText的值決定是否顯示text內容
let display = this.state.showText ? this.props.text : ’ ‘;
return (
{display}
);
}
}

class Test5 extends Component {
render() {
return (






);
}
}

AppRegistry.registerComponent(‘BlinkApp’, () => Test5);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章