Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

## Re: Zero 学习一个组件 #43

Open
hsipeng opened this issue Mar 21, 2018 · 0 comments
Open

## Re: Zero 学习一个组件 #43

hsipeng opened this issue Mar 21, 2018 · 0 comments

Comments

@hsipeng
Copy link
Owner

hsipeng commented Mar 21, 2018

#componet

class Clock extends React.Component{
  constructor(props){
    super(props);
    this.state = {date: new Date()}
  }
  
  componentDidMount(){
    this.Timer = setInterval(() => this._tick(), 1000);
  }
  
  componentWillUnMount(){
    clearInterval(this.Timer);
  }
  
  _tick(){
    this.setState({
      date: new Date()
    })
  }
  
  render() {
    return(<div> this is {this.state.date.toLocaleTimeString()}</div>)
  }
}

ReactDOM.render(
  <Clock />,
  document.getElementById('root')
);

知识点

  • ES6 的 class 是小写 小写 小写!!!
  • React.Componet 和 React.createClass
  • 生命周期(生命钩子)
  • 无状态组件和高阶组件
  • render 执行
  • 。。。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant