Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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