- 无状态组件优势
(1).代码整洁、可读性高
普通组件:
import React, { Component,PropTypes } from 'react';
export default class CusImg extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div cLassName={this.props.style}>
<img src={this.props.imgurl1}/>
<text cLassName={this.props.textStyle}>{this.props.text)</text>
</div >);
}
}
无状态组件:
import React, { Component, PropTypes } from 'react';
const CusImg = (props) => (
<div cLassName={props.style}>
<img src={props.imgurl1}/>
<text cLassName={props.textStyle}>{props.text}</text>
</div>
);
export default CusImg
(2).没有 this,因为使用的是箭头函数事件无需绑定。
(3).性能提升,因为没有生命周期的方法和状态。
(4).方便测试。
348

被折叠的 条评论
为什么被折叠?



