import React from 'react';
class Clock extends React.Component {
state = {date : new Date(),locale : 'bn-BD'};
componentDidMount(){
this.clockTimer = setInterval(() =>this.tick(), 1000);
}
componentWillUnmount(){
clearInterval(this.clockTimer);
}
tick(){
this.setState({
date : new Date(),
});
}
handelClick = () => {
this.setState({
locale: 'en-US',
});
}
render() {
const {data,locale}= this.state;
return(
<div>
<h1 className='heading'>
<span className='text'>{this.state.date.toLocaleTimeString(locale)}</span>
</h1>
<button type='button' onClick={this.handelClick}>Click Me</button>
</div>
);
}
}
export default Clock;
Comments
Post a Comment