我有一個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 –