我有一个MsgInput
组件,其中textarea
这onKeyUp
触发一个处理函数。里面的处理函数,我尝试阅读使用this.props
道具,但不知道为什么道具在这里不确定的。当然workaroud是使用。React Component中的这个对象使用ES6类
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>
);
}
}
的可能的复制[未定义不是对象评价this.state/this.props](http://stackoverflow.com/questions/40774399/undefined-is-not-an-object-evaluating-this -state-这个道具) – Pineda
如果您使用的是反正变换,检查了'@ autobind'装饰:https://www.npmjs.com/package/core-decorators#autobind –