Video Tutorial Our first component
In this chapter we will create our first React component. Components allow you to create reusable elements that will include their own logic and their own state. We will also discover the methods related to the life cycle of a component.
class Clock extends React.Component {
constructor (props) {
great (props)
this.state = {date: new Date ()}
this.timer = null
}
componentDidMount () {
this.timer = window.setInterval (this.tick.bind (this), 1000)
}
componentwillUnmount () {
window.clearInterval (this.timer)
}
tick () {
this.setState ({date: new Date ()})
}
render () {
return
It is {this.state.date.toLocaleDateString ()} {this.state.date.toLocaleTimeString ()}
}
}