react 中使用定时器 Timers(定时器)
- setTimeout,clearTmeout
- setInterval,clearInterval
在 class 中
- class TimersDemo extends Component {
- constructor(props) {
- super(props);
- this.state={
- content:'',
- }
- }
- componentDidMount() {
- this.timer = setTimeout(
- () => {
- this.setState({content:'我是定时器打印的内容...One'})
- },
- 500
- );
- this.timer_two = setTimeout(
- () => {
- this.setState({msg:'我是定时器打印的内容...Two'})
- },
- 1000
- );
- }
- componentWillUnmount() {
- this.timer && clearTimeout(this.timer);
- this.timer_two && clearTimeout(this.timer_two);
- }
- render() {
- return (
- <View style={{margin:20}}>
- <Text style={styles.welcome}>
- 定时器实例
- </Text>
- <Text>{this.state.content}</Text>
- <Text>{this.state.msg}</Text>
- </View>
- );
- }
- }
- setTimeout 延时的定时执行
- <CustomButton text='测试setInterval'
- onPress={()=>{
- this.interval=setInterval(() => {this.setState({sum:(this.state.sum+1)});
- },400);
- }}
- />
- <CustomButton text='clearInterval'
- onPress={()=>{
- this.interval && clearInterval(this.interval);
- }}
- />
- setInterval 定时间隔执行
react 中使用定时器 Timers(定时器)的更多相关文章
- 整理下react中常见的坑
其实有些也不能算是坑,有些是react的规定,或者是react的模式和平常的js处理的方式不同罢了 1.setState()是异步的this.setState()会调用render方法,但并不会立即改 ...
- 总结react中遇到的坑和一些小的知识点
在使用react 中经常会遇到各种个样的问题,如果对react不熟悉则会对遇到的问题感到莫名其妙而束手无策,接下来分析一下react中容易遇到的问题和注意点. 1.setState()是异步的this ...
- react中简单倒计时跳转
其实在react中实现倒计时的跳转方法有很多中,其中我认为较为好用的就是通过定时器更改state中的时间值. 首先在constructor中设置10秒的时间值: constructor () { su ...
- React中setState学习总结
react中setState方法到底是异步还是同步,其实这个是分在什么条件下是异步或者同步. 1.先来回顾一下react组件中改变state的几种方式: import React, { Compone ...
- React 中的 定义组件的 两种方式
React 中创建 Components 的方式有两种:Function and Class 定义一个组件最简单的方法就是写一个 JavaScript 函数 function Welcome(prop ...
- React中父子组件数据传递
Vue.js中父子组件数据传递:Props Down , Events Up Angular中父子组件数据传递:Props Down, Events Up React中父子组件数据传递:Prop ...
- STM32(5)——通用定时器基本定时器
1.STM32的Timer简介 STM32中一共有11个定时器,其中2个高级控制定时器,4个普通定时器和2个基本定时器,以及2个看门狗定时器和1个系统嘀嗒定时器. 其中系统嘀嗒定时器是前文中所描述的S ...
- 理解React中es6方法创建组件的this
首发于:https://mingjiezhang.github.io/(转载请说明此出处). 在JavaScript中,this对象是运行时基于函数的执行环境(也就是上下文)绑定的. 从react中的 ...
- 【原】React中,map出来的元素添加事件无法使用
在使用react中,经常用到react的map函数,用法和jquery里中的map一样,但是,如果你在每个map出来的元素中添加,你会发觉添加的事件无法关联, 比如,我们很多的评论,我需要在每个评论下 ...
随机推荐
- day 66 crm(3) 自创组件stark界面展示数据
前情提要: 接着上一节的.stark自创组件的展示效果编写 展示数据 一:按照默认自带数据展示 即无一对一,一对多 1:先获取queryset对象 2:获取当前操作模型表对象数据 注意:list_d ...
- POJ 1102
#include<iostream>// cheng da cai zi 11.14 using namespace std; int main() { int i; int j; int ...
- 使用ggbio在R中制作弦图
分享一个制作弦图的R包:ggbio. 以下是一个简单的使用实例,效果图和代码如下. library(GenomicRanges) set.seed(1) N <- 100 gr <- GR ...
- js的事件学习笔记
目录 0.参考 1.事件流 冒泡传播 事件捕获 2.事件绑定--onclick接口 onclick类的接口,只能注册一个同类事件 onclick类的接口,使用button.onclick = null ...
- (转)Python中集合(set)的基本操作以及一些常见的用法
原文:http://blog.51cto.com/10616534/1944841 Python除了List.Tuple.Dict等常用数据类型外,还有一种数据类型叫做集合(set),集合的最大特点是 ...
- 【转】使用SQL Server 2012的FileTable轻松管理文件
一 .FileStream和FileTable介绍 我们经常需要把结构化数据(int.Char等)和非结构化数据(如Varbinary(max))一起存储,那我们在怎么存储的呢? 1. 在SQL Se ...
- 【数组】Jump Game
题目: Given an array of non-negative integers, you are initially positioned at the first index of the ...
- C/C++ -- Gui编程 -- Qt库的使用 -- 纯代码实现信号槽
失败,系统找不着槽 #include<QtGui> int main(int argc, char * argv[]) { QApplication app(argc, argv); QT ...
- Redis笔记(二):Redis数据类型
Redis 数据类型 Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). String(字符串) st ...
- 使用Pelican在Github(国外线路访问)和Coding(国内线路访问)同步托管博客
本文原文地址:使用Pelican在Github(国外线路访问)和Coding(国内线路访问)同步托管博客 介绍: Github Pages 禁用了百度爬虫,因此百度搜索引擎经常抓取不到在Github上 ...