Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Last active August 19, 2020 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoneboyindc/d48eccf26ba83475ec995985725826e2 to your computer and use it in GitHub Desktop.
Save stoneboyindc/d48eccf26ba83475ec995985725826e2 to your computer and use it in GitHub Desktop.
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