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. bzoj1293: [SCOI2009]生日礼物

    单调队列 用一个堆维护目前每个颜色在里面的点,每回取出队首点,并更新答案.一旦哪个颜色的点都被用完,跳出循环. #include<cstdio> #include<algorithm ...

  2. HDU 5280 Senior's Array (暴力,水)

    题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. #include < ...

  3. 逻辑回归损失函数(cost function)

    逻辑回归模型预估的是样本属于某个分类的概率,其损失函数(Cost Function)可以像线型回归那样,以均方差来表示:也可以用对数.概率等方法.损失函数本质上是衡量”模型预估值“到“实际值”的距离, ...

  4. 扩展Oracle表空间

    1. 查看当前表空间利用率SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)" ...

  5. jquery-autocomplete 参数说明

    minChars (Number): 在触发autoComplete前用户至少需要输入的字符数.Default: 1,如果设为0,在输入框内双击或者删除输入框内内容时显示列表 * width (Num ...

  6. 手把手教你WEB套打程序开发

    WEB套打可选方案不多,理想的更少,利用免费控件Lodop+JavaScript实现精确套打,算是较为经典的选择.这种方案其实比较简单,利用一个htm文件就可以实现模板设计过程,几乎是“空手套”式的开 ...

  7. HDU 5007 Post Robot

    Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  8. 无法找到.exe的调试信息

    原文:无法找到.exe的调试信息 前天重装了电脑,并配置了Visual Studio2005的VC正则库,boost/regex,运行速度马上快了三倍吧,到底是怎么快的,我还真说不清楚,因为电脑这玩意 ...

  9. (Android Studio)添加文本框

    此文大部分摘自http://hukai.me/android-training-course-in-chinese/basics/firstapp/building-ui.html android : ...

  10. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.3

    Let $\scrM$ be a $p$-dimensional subspace of $\scrH$ and $\scrN$ its orthogonal complement. Choosing ...