Skip to content

Instantly share code, notes, and snippets.

@jonnung
Last active April 27, 2016 09:28
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 jonnung/6140ae8f8f3db9df014854f60dc33415 to your computer and use it in GitHub Desktop.
Save jonnung/6140ae8f8f3db9df014854f60dc33415 to your computer and use it in GitHub Desktop.
[DalkStudy] react-webpack-starter-example.js
var React = require('react');
var ReactDOM = require('react-dom');
var RandomMessage = React.createClass({
getInitialState: function () {
return { message: "Hello, React!" };
},
onClick: function () {
var messages = ['Hello, DalkStudy', 'Hello, Jonnung', 'Hello, Gaerae'];
var randomMessage = messages[Math.floor(Math.random() * 3)];
this.setState({ message: randomMessage});
},
render: function () {
return (
<div>
<MessageView message={ this.state.message } />
<p>
<input type="button" onClick={ this.onClick } value="Change message" />
</p>
</div>
)
}
});
var MessageView = React.createClass({
render: function () {
return (
<p>{ this.props.message }</p>
);
}
});
ReactDOM.render(
<RandomMessage />,
document.getElementById('greeting-div')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment