A Pen by Matthew Henderson on CodePen.
Last active
July 2, 2019 08:36
-
-
Save MHenderson/aeff7e1c25ea6664dbce7154e4fc1bc8 to your computer and use it in GitHub Desktop.
react-hello-world
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
<div id="timer-example"></div> |
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
class Timer extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { seconds: 0 }; | |
} | |
tick() { | |
this.setState(state => ({ | |
seconds: state.seconds + 1 | |
})); | |
} | |
componentDidMount() { | |
this.interval = setInterval(() => this.tick(), 1000); | |
} | |
componentWillUnmount() { | |
clearInterval(this.interval); | |
} | |
render() { | |
return ( | |
<div> | |
Seconds: {this.state.seconds} | |
</div> | |
); | |
} | |
} | |
ReactDOM.render( | |
<Timer />, | |
document.getElementById('timer-example') | |
); |
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
<script src="//unpkg.com/react/umd/react.development.js"></script> | |
<script src="//unpkg.com/react-dom/umd/react-dom.development.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.6/umd/react.production.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment