React.Componentrender()JSX
class Clock extends React.Component { // render函数表示渲染,每次重新渲染都要调用该函数 render(){ return ( <div> <h2>Clock, {this.props.name}</h2> </div> ); } } state
UIstatesuper(props)
class Clock extends React.Component { constructor(props){ //props形参在构造器中,和函数组件不一样 super(props); this.state = { now:new Date().toLocaleString() } } } state
1state
this.setState()
2State
setStatestate
componentDidMount
setState
componentWillUnmount
'onXxx'thisrender()
this
es6this为undefinedthisthis