Last active
August 8, 2016 15:17
-
-
Save jnsprnw/0d94071dea8e289dc6d3739fb23a2816 to your computer and use it in GitHub Desktop.
Basic default ES6 React Component
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
import React, { PropTypes, Component } from 'react'; | |
export default class MessageComponent extends Component { | |
constructor(props) { | |
super(props); | |
// Get list of all functions | |
// _.each(Object.getOwnPropertyNames(Object.getPrototypeOf(this)), (o) => { | |
// if(_.indexOf(['constructor', 'render'], o) < 0 && _.isFunction(this[o])) { | |
// this[o] = this[o].bind(this); | |
// }; | |
// }); | |
// Define list of functions to be binded | |
_.each(['foo'], (f) => { | |
if(_.isFunction(this[f])) { | |
this[f] = this[f].bind(this); | |
}; | |
}); | |
} | |
foo() { | |
const { name } = this.props; | |
console.log(`Hallo ${name}`); | |
} | |
render() { | |
const { name } = this.props; | |
return ( | |
<div>Hallo {message}</div> | |
); | |
} | |
} | |
MessageComponent.propTypes = { | |
name: React.PropTypes.string.isRequired, | |
}; | |
MessageComponent.defaultProps = { | |
name: 'Pikachu', | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment