Skip to content

Instantly share code, notes, and snippets.

@michaelrambeau
Last active August 29, 2015 14:17
Show Gist options
  • Save michaelrambeau/7ba9b6401213415bdb21 to your computer and use it in GitHub Desktop.
Save michaelrambeau/7ba9b6401213415bdb21 to your computer and use it in GitHub Desktop.
var MyComponent = React.createClass({
getDefaultProps: function() {
return {
title: 'My defaut title'
};
},
getInitialState: function() {
return {
counter: 0
};
},
onClick: function () {
this.setState({
counter: this.state.counter + 1
});
},
render: function() {
return (
<div>
{ this.props.title }
{ this.state.counter }
<button onClick={ this.onClick }>INCREMENT</button>
</div>
);
}
});
var options = {
title: 'My component'
};
React.render(
React.createElement(MyComponent, options),
document.getElementById('app')
);
<button>Cancel</button>
{' '}
<button>OK</button>
<body>
<br>
<MyApp>
</body>
=> Error "Expected corresponding XJS closing tag for MyApp"
<body>
<br />
<MyApp />
</body>
=> OK!
onDeleteAll: function (event) {
},
render: function() {
return (
<button onClick={ this.onDeleteAll }>Delete All</button>
);
}
onEmailAction: function (email, actionCode, event) {
},
render: function() {
return (
<button
onClick={ this.onEmailAction.bind(null, email, 'MARK_AS_READ') }>
Mark as read
</button>
);
}
var EmailFilterList = React.createClass({
mixins: [FilterListEventMixin],
render: function() {
...
var MySection = React.createClass({...});
MySection.Title = React.createClass({...});
MySection.Body = React.createClass({...});
<MySection>
<MySection.Title>My title</MySection.Title>
<MySection.Body>
...
</MySection.Body>
</MySection>
React.createClass({
propTypes: {
myOptionalArray: React.PropTypes.array
}
...
myRequiredArray: React.PropTypes.array.isRequired
<MySubComponent items={ ['A', 'B'] } onSave={ saveFunction } />
<button className="btn btn-default">
{ term == 'yearly' && (
<p>10%値引き<p>
) }
{ term == 'monthly' ? (
<span>1ヶ月</span>
) : (
<span>12ヶ月</span>
)}
<span>{ term == 'monthly' ? '1ヶ月' : '12ヶ月' }</span>
render: function() {
var menuItem = function(i) {
return(
<li>
<span>{'STEP' + i }</span>
</li>
);
};
return(
  <ul>
  { [1, 2, 3].map(menuItem) }
  </ul>
);
}
style={{ float: 'right', padding: 10 }}
componentDidMount: function () {
var el = this.getDOMNode();
var $el = $(el);
var $form = $el.find('form');
$form.mySuperPlugin();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment