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的更多相关文章

  1. [React ] React Fundamentals: Component Lifecycle - Mounting Usage

    The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson ...

  2. [React Fundamentals] Component Lifecycle - Mounting Basics

    React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...

  3. [React] React Fundamentals: Component Lifecycle - Mounting Basics

    React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...

  4. [React Fundamentals] Component Lifecycle - Updating

    The React component lifecycle will allow you to update your components at runtime. This lesson will ...

  5. [React] React Fundamentals: Component Lifecycle - Updating

    The React component lifecycle will allow you to update your components at runtime. This lesson will ...

  6. React.js Tutorial: React Component Lifecycle

    Introduction about React component lifecycle. 1 Lifecycle A React component in browser can be any of ...

  7. React (Native) Rendering Lifecycle

    How Does React Native Work? The idea of writing mobile applications in JavaScript feels a little odd ...

  8. React & styled component

    React & styled component https://www.styled-components.com/#your-first-styled-component tagged t ...

  9. react slot component with args

    react slot component with args how to pass args to react props child component https://codesandbox.i ...

随机推荐

  1. 取出block所对应的hash值

    /**********************************************************************//** Gets the hash value of t ...

  2. linq .dbml转化成sql脚本

    public String ConvertDBMLToSqlScript(System.Data.Linq.DataContext DBContext)  {         String DBCon ...

  3. 百度地图API的调用

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  4. [POJ 2461] Billiard

    同swustoj 11 Billiard Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1362   Accepted: 8 ...

  5. [POJ 1365] Prime Land

    Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3211   Accepted: 1473 Descri ...

  6. PSR-4——新鲜出炉的PHP规范

    FIG 制定的PHP规范,简称PSR,是PHP开发的事实标准. PSR原本有四个规范,分别是: PSR-0 自动加载 PSR-1 基本代码规范 PSR-2 代码样式 PSR-3 日志接口 2013年底 ...

  7. JQuery: 微博演示

    演示图: 完成图: 微博演示代码如下: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> ...

  8. Mtom Encoding in WCF

    http://www.codeproject.com/Articles/632101/Mtom-Encoding-in-WCF http://msdn.microsoft.com/zh-cn/libr ...

  9. 线性表-串:KMP模式匹配算法

    一.简单模式匹配算法(略,逐字符比较即可) 二.KMP模式匹配算法 next数组:j为字符序号,从1开始. (1)当j=1时,next=0: (2)当存在前缀=后缀情况,next=相同字符数+1: ( ...

  10. Good Bye 2015 C - New Year and Domino

    题意:计算给定矩形面积(r1,c1),(r2,c2)内长度为2的有多少个?向右或向下计算. 思路:预处理字符.分别向右和向下处理.注意边界情况,可能算多了.用容斥原理计算长度为二的单位. #inclu ...