formations/developpement/intro_javascript/ressources/react-demo/components/clock.js

27 lines
377 B
JavaScript
Raw Normal View History

import React from 'react'
class Clock extends React.Component {
constructor(props) {
super(props)
this.state = {
time: new Date()
}
setInterval(this.tick.bind(this), 1000);
}
render() {
return (
<div>Time: { this.state.time.toString() }</div>
)
}
tick() {
this.setState({ time: new Date() });
}
}
export default Clock