Skip to content

Instantly share code, notes, and snippets.

@nickdima
Last active August 29, 2015 14:25
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 nickdima/103c4bf7254e26547b4a to your computer and use it in GitHub Desktop.
Save nickdima/103c4bf7254e26547b4a to your computer and use it in GitHub Desktop.

Component Definition

CoffeeScriptJavaScript
class Comp extends React.Component
@propTypes:
name: React.PropTypes.string
@defaultProps:
name: 'Nick'
state:
disabled: false
greet: =>
alert 'Hi ' + @props.name
@setState disabled: true
render: ->
<button
disabled={@state.enabled}
onClick={@greet}>
Click Me!
</button>
class Comp extends React.Component {
constructor(props) {
super(props);
this.state = {
disabled: false
};
}
greet() {
alert('Hi ' + this.props.name);
this.setState({disabled: true});
}
render() {
return (
<button
disabled={this.state.disabled}
onClick={this.greet.bind(this)}>
Click Me!
</button>
);
}
}
Comp.propTypes = {
name: React.PropTypes.string
};
Comp.defaultProps = {
name: 'Nick'
};

Arrow Functions

In CoffeeScript...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment