[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 ...
随机推荐
- 十个免费的Web压力测试工具
两天,jnj在本站发布了<如何在低速率网络中测试 Web 应用>,那是测试网络不好的情况.而下面是十个免费的可以用来进行Web的负载/压力测试的工具,这样,你就可以知道你的服务器以及你的W ...
- BZOJ2542: [Ctsc2001]终极情报网
题解: 乘积最小只需要取对数.然后反向边就变成1/c,而不是-c了. 精度问题搞得我已经我想说什么了... 贴一份网上的pascal 代码: type ss=record x,y,c,r,next:l ...
- vijos1603迷宫
这题的构思太巧妙了: 经典题目8 给定一个有向图,问从A点恰好走k步(允许重复经过边)到达B点的方案数mod p的值 把给定的图转为邻接矩阵,即A(i,j)=1当且仅当存在一条边i->j. ...
- Vim Vundle 插件管理器
/********************************************************************** * Vim Vundle 插件管理器 * 说明: * 话 ...
- centos nginx 多端口配置过程记录
1. 编辑 /usr/local/nginx/vhosts/ 在此目录下增加一文件,如;ci.ainux.com,或复制一个文件 修改其中的端口和目录,更改log_format 名称 重启nginx ...
- 【 D3.js 高级系列 — 4.0 】 矩阵树图
矩阵树图(Treemap),也是层级布局的扩展,根据数据将区域划分为矩形的集合.矩形的大小和颜色,都是数据的反映.许多门户网站都能见到类似图1,将照片以不同大小的矩形排列的情形,这正是矩阵树图的应用. ...
- Azure HDInsight与Hadoop周边系统集成
Sunwei 9 Dec 2014 1:54 AM 传统的Hadoop系统提供给用户2个非常优秀的框架,MR计算框架和HDFS存储框架,尽管MR已经显得有些老迈而缓慢,但是HDFS还是很多应用系统的 ...
- 【转】ubuntu 编码 UTF-8 GBK GB18030
添加编码支持 sudo locale-gen zh_CN.GBK sudo locale-gen zh_CN.GB2312 sudo locale-gen zh_CN.GB18030 2.更新一下lo ...
- init进程学习
linux的init进程 一个在线编辑markdown文档的编辑器,是内核启动的第一个进程,init进程有很多重要的任务,它的pit 为1,在linux shell中使用pstree命令可以看到它为其 ...
- Esper系列(十四)Contained-Event Selection
功能:该语法是针对所查询事件中的属性又是另一种属性的查询结果控制. 格式: 1 "+j); 19 bean.setBean(item); 20 list.add(bea ...