[React Fundamentals] Component Lifecycle - Mounting Usage
The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson you will learn some simple uses for these hooks.
import React from 'react';
import ReactDOM from 'react-dom'; class App extends React.Component {
constructor(){
super();
this.state = {
val:
}
}
update(){
this.setState({val: this.state.val + })
}
componentWillMount(){
console.log(this.state)
this.setState({
val: this.state.val *
});
console.log("Component Will Mount");
}
render() {
console.log("rendering");
return (
<div>
<button onClick={this.update.bind(this)}>{this.state.val}</button>
</div>
)
}
componentDidMount(){
this.inc = setInterval(this.update.bind(this), );
console.log("Component Did Mount");
}
componentWillUnmount(){
clearInterval(this.inc);
console.log("Component will unmount");
}
} export default class Wrapper extends React.Component{
constructor(){
super();
}
mount(){
ReactDOM.render(<App />, document.getElementById('a'));
}
unmount(){
// Unmount a dom node
ReactDOM.unmountComponentAtNode(document.getElementById('a'))
}
render() {
return (
<div>
<button onClick={this.mount.bind(this)}>Mount</button>
<button onClick={this.unmount.bind(this)}>Unmount</button>
<div id="a"></div>
</div>
);
} }
[React Fundamentals] Component Lifecycle - Mounting Usage的更多相关文章
- [React ] React Fundamentals: Component Lifecycle - Mounting Usage
The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson ...
- [React Fundamentals] Component Lifecycle - Mounting Basics
React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...
- [React] React Fundamentals: Component Lifecycle - Mounting Basics
React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...
- [React Fundamentals] Component Lifecycle - Updating
The React component lifecycle will allow you to update your components at runtime. This lesson will ...
- [React] React Fundamentals: Component Lifecycle - Updating
The React component lifecycle will allow you to update your components at runtime. This lesson will ...
- React.js Tutorial: React Component Lifecycle
Introduction about React component lifecycle. 1 Lifecycle A React component in browser can be any of ...
- React (Native) Rendering Lifecycle
How Does React Native Work? The idea of writing mobile applications in JavaScript feels a little odd ...
- React & styled component
React & styled component https://www.styled-components.com/#your-first-styled-component tagged t ...
- react slot component with args
react slot component with args how to pass args to react props child component https://codesandbox.i ...
随机推荐
- 变量赋值(引用) php内核的实现(二)
<?php $a=1; $b=&$a; $c=2; $a=&$c; echo $a."\n"; echo $b; 2 1 结论: 首先保存 左值的内存地址, ...
- UVa 120 (构造) Stacks of Flapjacks
这题求解的过程和选择排序非常相似. 反转的过程中分为无序(在前面)和有序(在后面)两个部分,一开始视为全部为无序. 在无序部分中找到最大的元素,先把它翻到最前面,然后再反转到无序部分的最后面.这样该元 ...
- 关于Azure存储账户中存储虚拟机VHD文件的注意事项
Joy Qiao from MSFT Thu, Mar 12 2015 3:16 PM 我们在使用Azure时经常都会在Azure存储账户中放一些文件,包括Azure虚机的VHD文件也都是放在存储 ...
- android ListView详解
转自:http://www.cnblogs.com/allin/archive/2010/05/11/1732200.html 在android开发中ListView是比较常用的组件,它以列表的形式展 ...
- 使用 Apache MINA2 实现 Web 系统的消息中间件
本文将介绍如何使用 Apache MINA2(以下简称 MINA2)解决复杂 Web 系统内各子系统之间同步消息中间件的问题.MINA2 为开发高性能和高可用性的网络应用程序提供了非常便利的框架.从本 ...
- 黑盒测试用例设计方法&理论结合实际 -> 判定表驱动法
一. 概念 判定表是分析和表达多逻辑条件下执行不同操作的情况的工具. 二. 判定表驱动法的应用 判定表的优点: a. 能够将复杂的问题按照各种可能的情况全部列举出来,简明并避免遗漏.因此,利用判定表能 ...
- 利用weka和clementine数据挖掘举例
1.数据概述 本报告中采用的数据集来自于UCI经典数据集Adult,最初来源是由1994年Barry Becker的统计数据集,该数据集本来最初的主要任务是根据数据集中的相关属性预测某个人的年收入是大 ...
- leetcode—Same Tree
1.题目描述 Given two binary trees, write a function to check if they are equal or not. Two binary tree ...
- leetcode@ [49] Group Anagrams (Hashtable)
https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For exam ...
- HDU2296——Ring(AC自动机+DP)
题意:输入N代表字符串长度,输入M代表喜欢的词语的个数,接下来是M个词语,然后是M个词语每个的价值.求字符串的最大价值.每个单词的价值就是单价*出现次数.单词可以重叠.如果不止一个答案,选择字典序最小 ...