Update snippets/Timer.md
Co-Authored-By: arjunmahishi <arjun.mahishi@gmail.com>
This commit is contained in:
@ -20,7 +20,7 @@ class Timer extends Component {
|
|||||||
this.reset()
|
this.reset()
|
||||||
this.interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
if (this.state.timer < this.props.time) {
|
if (this.state.timer < this.props.time) {
|
||||||
this.setState({timer: this.state.timer + 1})
|
this.setState(({ timer }) => ({timer: timer + 1}))
|
||||||
}else{
|
}else{
|
||||||
clearInterval(this.interval)
|
clearInterval(this.interval)
|
||||||
}
|
}
|
||||||
@ -46,4 +46,4 @@ class Timer extends Component {
|
|||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
ReactDOM.render(<Timer time={5} interval={1000} />, document.getElementById('root'));
|
ReactDOM.render(<Timer time={5} interval={1000} />, document.getElementById('root'));
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user