React笔记整理
大概大半年时间都在用react写项目,一直在笔记上零零星星地记录着,在新的一年即将到来之际,打算整理整理发出来。
class
在 JSX 里要写成 className
,因为 class
在 JS 里是保留关键字。同理某些属性比如for
要写成 htmlFor
。class Counter extends Component {
constructor(props) {
super(props);
this.state = { count: props.initialCount };
}
render() {
// ...
}
}
使用 ES6 语法,可以直接定义 defaultProps
这个类属性来替代,这样能更直观的知道 default props 是预先定义好的对象值:
Counter.defaultProps = { initialCount: 0 };
render
(1)componentWillMount
render
之前调用,你可以在这个方法里面调用 setState
改变状态,并且不会导致额外调用一次 render
(2)componentDidMount
render
之后调用,从这里开始可以通过 ReactDOM.findDOMNode(this)
获取到组件的 DOM 节点。这些方法不会在首次 render
组件的周期调用
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
componentDidUpdate
statics
对象允许你定义静态的方法,这些静态的方法可以在组件类上调用;在这个块儿里面定义的方法都是静态的,意味着你可以在任何组件实例创建之前调用它们,这些方法不能获取组件的 props 和 state。如果你想在静态方法中检查 props 的值,在调用处把 props 作为参数传入到静态方法。表单组件可以通过 onChange
回调函数来监听组件变化。当用户做出以下交互时,onChange
执行并通过浏览器做出响应:
<input>
或<textarea>
的value
发生变化时。<input>
的checked
状态改变时。<option>
的selected
状态改变时。
类型为 radio
、checkbox
的<input>
支持 defaultChecked
属性, <select>
支持 defaultValue
属性。




.png)
this.props.key
from a component (eg. the render function) is not defined. If you need to access the same value within the child component, you should pass it as a different prop (ex: <ListItemWrapper key={result.id} id={result.id} />
). 

.png)
ref
and key
) which are used by React, and are thus not forwarded to the componentin i (created by Rules (bindStores))
in div (created by Rules (bindStores))
in div (created by Rules (bindStores))
<i style={{float:'right',marginRight:'7px'}} data-tip={__('仅供查询报警对象名称')} place="top" className="iconfont tips"></i>
即一些自定义的元素,最好使用 data- 放在开头。
好了,本人不才,先到此为止。
React笔记整理的更多相关文章
- React 入门学习笔记整理目录
React 入门学习笔记整理(一)--搭建环境 React 入门学习笔记整理(二)-- JSX简介与语法 React 入门学习笔记整理(三)-- 组件 React 入门学习笔记整理(四)-- 事件 R ...
- 学习ReactNative笔记整理一___JavaScript基础
学习ReactNative笔记整理一___JavaScript基础 ★★★笔记时间- 2017-1-9 ★★★ 前言: 现在跨平台是一个趋势,这样可以减少开发和维护的成本.第一次看是看的ReactNa ...
- python学习笔记整理——字典
python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...
- 从0开始学Swift笔记整理(五)
这是跟在上一篇博文后续内容: --Core Foundation框架 Core Foundation框架是苹果公司提供一套概念来源于Foundation框架,编程接口面向C语言风格的API.虽然在Sw ...
- React笔记_(3)_react语法2
React笔记_(3)_react语法2 state和refs props就是在render渲染时,向组件内传递的变量,这个传递是单向的,只能继承下来读取. 如何进行双向传递呢? state (状态机 ...
- Deep Learning(深度学习)学习笔记整理系列之(五)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(八)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(七)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(六)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
随机推荐
- 图解atime/mtime/ctime之间的区别与联系
补充:
- 转摘 MySQL扫盲篇
一下文章摘自:http://www.jellythink.com/archives/636 MySQL扫盲篇 2014-09-15 分类:MySQL / 数据库 阅读(1412) 评论(1) 为什么 ...
- gmc银联接口开发demo
1.接口文档 1.1 无gmc界面接口 (dll/ocx) dll调用(posinf.dll)函数名为:int bankall (char * request,char *response),其中第一 ...
- 使用openvswitch 和dnsmasq来实现虚拟机网络隔离
openvswicth : 开源的网络虚拟化软件,可以划分vlan隔离虚拟机,做流量控制 dnsmasq:小心的dns,dhcp服务器 安装openvswicth wget http://openv ...
- iOS JavaScriptCore与H5交互时出现异常提示
在利用JavaScriptCore与H5交互时出现异常提示: This application is modifying the autolayout engine from a background ...
- Linux环境安装MySQL数据库
1. 下载mysql安装包 下载地址1: http://www.mysql.com/ (mysql官网) 下载地址2: http://mirrors.sohu.com/mysql/ (其 ...
- WPF打包32位和64位程序 运行在ghost WIN7上问题
WIN10,VS2015,编译平台"anycpu".WIN7系统为ghost版 1. 在.NET4.5下编译,程序打包以后,在WIN7上运行界面启动有3.4秒的延迟:将.NET版本 ...
- varnish 隐藏版本号
varnish 隐藏方法: 修改default.vcl配置文件. 找到或添加 vcl_deliver 子程序,代码如下: 1 2 3 4 5 sub vcl_deliver { unse ...
- PRML读书笔记——3 Linear Models for Regression
Linear Basis Function Models 线性模型的一个关键属性是它是参数的一个线性函数,形式如下: w是参数,x可以是原始的数据,也可以是关于原始数据的一个函数值,这个函数就叫bas ...
- Dll的生成,转化为OMF格式的DLL
extern "C" { __declspec(dllexport) int psq_add(int a, int b); } C:\Users\pansq>mkexp my ...