react学习:组件&props

匿名 (未验证) 提交于 2019-12-02 23:57:01

定义组件

1.函数定义组件:(此函数为有效的React组件,它接收一个单一的“props”对象并返回了一个React元素)

function Welcome(props) {

  return  <div>hello , {props.name}</div>

}

2.使用es6的class进行定义

class Welcome extends React.Component(

  render(

    return <div>hello , {this.props.name}</div>

  )

)

小结:两种定义在react中是一样的。

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!