Created
June 25, 2018 10:05
-
-
Save kdastan/2cfc72388df60167fafb678943b489db to your computer and use it in GitHub Desktop.
counter 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
<div id="root"></div> | |
<script src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> | |
<script type="text/babel"> | |
const rootElement = document.getElementById('root'); | |
class App extends React.Component { | |
state = { | |
counter: 0 | |
} | |
handleClick = () => { | |
this.setState({ counter: ++this.state.counter}) | |
} | |
render() { | |
return ( | |
<div> | |
<div> {this.state.counter} </div> | |
<Button | |
boxName="Click Me" | |
onClick={this.handleClick} | |
/> | |
</div> | |
) | |
} | |
} | |
class Button extends React.Component { | |
render() { | |
return ( | |
<div onClick={this.props.onClick}> | |
{this.props.boxName} | |
</div> | |
) | |
} | |
} | |
ReactDOM.render(<App />, rootElement) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment