Last active
August 19, 2020 18:49
-
-
Save stoneboyindc/d48eccf26ba83475ec995985725826e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default class Bomb extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { count: 0 }; | |
} | |
componentDidMount() { | |
this.interval = setInterval(() => { | |
this.setState({count: this.state.count + 1}) | |
}, 1000) | |
} | |
componentWillUnmount() { | |
clearInterval(this.interval) | |
} | |
render() { | |
let renderedText = ""; | |
if (this.state.count >= 8) { | |
renderedText = 'KABOOM!'; | |
clearInterval(this.interval); | |
} else if (this.state.count % 2) { | |
renderedText = 'tick' | |
} else { | |
renderedText = 'tock' | |
} | |
return ( | |
<div><p>{renderedText}</p></div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment