I have a MsgInput component with a textarea which onKeyUp triggers a handler function. Inside the handler function, I try reading the props using this.props, but not sure why props is undefined here. Ofcourse the workaroud is to use this.handler.bind(this).
export class MsgInput extends React.Component {
constructor(props) {
super(props);
}
inputHandler(e) {
if(e.keyCode == 13 && !e.shiftKey) {
this.props.onNewMessage({content: e.target.value});
e.target.value = '';
e.preventDefault();
}
}
render() {
return (
<div className="controls">
<textarea onKeyDown={this.inputHandler.bind(this)} className="msg-input" placeholder="Write something" disabled={!this.props.auth}></textarea>
</div>
);
}
}
@autobinddecorator: npmjs.com/package/core-decorators#autobind