[英]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.