Skip to content

Instantly share code, notes, and snippets.

@Rplus
Last active May 4, 2018
Embed
What would you like to do?
<script src="https://unpkg.com/react@15/dist/react.min.js"> </script><script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js">
</script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<div id="root"></div>
<script type="text/babel">
class Hello extends React.Component {
constructor(){
super();
this.state = {
message: "my friend (from state)!"
};
}
updateMessage = () => {
this.setState({
message: "my friend (from changed state)!"
});
}
render() {
return (
<div>
<h1>Hello {this.state.message}!</h1>
<button onClick={this.updateMessage}>Click me!</button>
</div>
)
}
}
ReactDOM.render(
<Hello message="my friend" />,
document.getElementById("root")
);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment