React-Native 基础(三) 使用State改变状态
发布时间:2020-12-15 03:26:19 所属栏目:百科 来源:网络整理
导读:参考文档: http://reactnative.cn/docs/next/state.html#content http://reactnative.cn/docs/next/state.html#content 我们使用两种数据来控制一个组件:props和state. props定制的内容,一经组件创建,内容不再改变。 需要改变的数据使用state. 使用state
参考文档: 我们使用两种数据来控制一个组件:props和state. 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() {
let display = this.state.showText ? this.props.text : ' ';
return (
<Text>{display}</Text>
);
}
}
class BlinkApp 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>
);
}
}
AppRegistry.registerComponent('BlinkApp',() => BlinkApp);
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ajax – 此请求已被阻止;内容必须通过HTTPS提供
- 跟着官方教程学习cocos2d-x(一)win7,Android环境配置
- 使用C#API使用SSPI对vSphere进行身份验证
- 点击 VB 中 DataGrid 行 触发事件 弹出窗口 并传递 所点击行
- FlashDevelop / FlashBuilder 常用快捷键
- c# – 自动增量属性不是键
- c# – 从同一进程托管和使用WCF服务
- FMS3系列(六):使用远程共享对象(SharedObject)实现多人时时
- c# – 为什么使用FlagsAttribute定义EntityState枚举
- ruby-on-rails – 覆盖类和实例方法的method_missing?