Last active
August 29, 2015 14:17
-
-
Save michaelrambeau/7ba9b6401213415bdb21 to your computer and use it in GitHub Desktop.
React Memo ref: http://qiita.com/michaelrambeau/items/d6bdee0c98c7d9bad009
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
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> | |
); | |
} | |
}); |
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
var options = { | |
title: 'My component' | |
}; | |
React.render( | |
React.createElement(MyComponent, options), | |
document.getElementById('app') | |
); |
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
<button>Cancel</button> | |
{' '} | |
<button>OK</button> |
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
<body> | |
<br> | |
<MyApp> | |
</body> | |
=> Error "Expected corresponding XJS closing tag for MyApp" |
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
<body> | |
<br /> | |
<MyApp /> | |
</body> | |
=> OK! |
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
onDeleteAll: function (event) { | |
}, | |
render: function() { | |
return ( | |
<button onClick={ this.onDeleteAll }>Delete All</button> | |
); | |
} |
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
onEmailAction: function (email, actionCode, event) { | |
}, | |
render: function() { | |
return ( | |
<button | |
onClick={ this.onEmailAction.bind(null, email, 'MARK_AS_READ') }> | |
Mark as read | |
</button> | |
); | |
} |
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
var EmailFilterList = React.createClass({ | |
mixins: [FilterListEventMixin], | |
render: function() { | |
... | |
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
var MySection = React.createClass({...}); | |
MySection.Title = React.createClass({...}); | |
MySection.Body = React.createClass({...}); | |
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
<MySection> | |
<MySection.Title>My title</MySection.Title> | |
<MySection.Body> | |
... | |
</MySection.Body> | |
</MySection> |
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
React.createClass({ | |
propTypes: { | |
myOptionalArray: React.PropTypes.array | |
} | |
... |
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
myRequiredArray: React.PropTypes.array.isRequired |
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
<MySubComponent items={ ['A', 'B'] } onSave={ saveFunction } /> |
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
<button className="btn btn-default"> |
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
{ term == 'yearly' && ( | |
<p>10%値引き<p> | |
) } |
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
{ term == 'monthly' ? ( | |
<span>1ヶ月</span> | |
) : ( | |
<span>12ヶ月</span> | |
)} |
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
<span>{ term == 'monthly' ? '1ヶ月' : '12ヶ月' }</span> |
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
render: function() { | |
var menuItem = function(i) { | |
return( | |
<li> | |
<span>{'STEP' + i }</span> | |
</li> | |
); | |
}; | |
return( | |
<ul> | |
{ [1, 2, 3].map(menuItem) } | |
</ul> | |
); | |
} |
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
style={{ float: 'right', padding: 10 }} |
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
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