Skip to content

Instantly share code, notes, and snippets.

@jnsprnw
Last active August 8, 2016 15:17
Show Gist options
  • Save jnsprnw/0d94071dea8e289dc6d3739fb23a2816 to your computer and use it in GitHub Desktop.
Save jnsprnw/0d94071dea8e289dc6d3739fb23a2816 to your computer and use it in GitHub Desktop.
Basic default ES6 React Component
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