[英]Uncaught TypeError: Cannot read property 'props' of null in React
这是我的子组件,需要将数据传递给它的父组件。
class Sidebar extends React.Component {
getUserInput(event){
event.preventDefault();
let value = document.getElementById('input-button').value;
console.log(value);
this.props.handleSubmit(value);
}
render() {
return (
<div>
<input type="text" id="input-button" placeholder="YGUID" />
<button type="button" className="btn btn-info btn-icons" onClick={this.getUserInput} />
</div>
);
}
}
Sidebar.propTypes = {
handleSubmit: React.PropTypes.func
};
父级在此处调用handleSubmit。
......
handleSubmit(data){
console.log(data);
}
render(){
return(
<div className="col-md-2 left-pane">
<Sidebar handleSubmit= {this.handleSubmit}/>
</div>
);
}
我收到以下错误。
Uncaught TypeError: Cannot read property 'props' of null
我在这里做错了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.