React创建组件的三种方式比较和入门实例

推荐文章: https://www.cnblogs.com/wonyun/p/5930333.html

  创建组件的方式主要有:

  1、function 方式

  2、class App extends React.component {}

  3. React.creatClass

大致区别: function创建组件的方式最为高效,但是其只能传递props,而不能使用状态等。 extends React.component 的方式功能更为强大,他不仅可以通案过 this.props 来使用prop并且还可以使用状态管理,另外,还可以通过 extends 继承 React.pureComponent ,这样,我们就更加容易使用钩子函数等。

{array}变量展开数组全部成员

React.Children.map(this.props.children, function (child) {

return <li>{child}</li>;

})

无子节点 undefined 1:对象 2:数组

getDefaultProps getInitialState this.props表示那些一旦定义,就不再改变的特性,而 this.state是会随着用户互动而产生变化的特性。{{}}组件样式为对象,1为标识2为对象

阮一峰:http://www.ruanyifeng.com/blog/2015/03/react.html