Skip to content

Instantly share code, notes, and snippets.

@RyanAtViceSoftware
Last active December 19, 2015 16:41
Show Gist options
  • Save RyanAtViceSoftware/a0f84933027e0a1a2a38 to your computer and use it in GitHub Desktop.
Save RyanAtViceSoftware/a0f84933027e0a1a2a38 to your computer and use it in GitHub Desktop.
Hello React - mixins - updating events. JsFiddle: http://jsfiddle.net/gh/gist/library/pure/a0f84933027e0a1a2a38
<script src="https://fb.me/react-with-addons-0.14.0.js"></script>
<script src="https://fb.me/react-dom-0.14.0.js"></script>
<div id="view"/>
var ReactMixin1 = {
log: function(message) {
console.log(message);
},
componentWillMount: function() {
this.log('componentWillMount from ReactMixin1');
}
};
var ReactMixin2 = {
componentWillMount: function() {
console.log('componentWillMount from ReactMixin2');
}
};
var HelloMessage = React.createClass({
mixins: [ReactMixin1, ReactMixin2],
componentWillMount: function() {
this.log('componentWillMount from HelloMessage');
},
render: function() {
return <h2>{this.props.message}</h2>;
}
});
var Button = React.createClass({
mixins: [ReactMixin2, ReactMixin1],
clicked: function() {
this.log(this.props.text + ' clicked');
},
componentWillMount: function() {
this.log('componentWillMount from Button');
},
render: function() {
return <button onClick={this.clicked}>{this.props.text}</button>
}
});
var HelloReact = React.createClass({
render: function() {
return (
<div>
<HelloMessage message='Hi'/>
<Button text='OK'/>
</div>
);
}
});
ReactDOM.render(
<HelloReact/>,
document.getElementById('view'));
name: ReactJs example by Ryan Vice - www.ViceSoftware.com
description: Hello React - mixins - updating events.
authors:
- Ryan Vice
resources:
- https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css
normalize_css: no
wrap: h
panel_js: 3
panel_css: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment