我正在学习 React JS,同时学习在线教程。下面的代码停止工作并给我一个异常“TypeError:无法读取未定义的属性'PreventDefault'”。有人可以帮我理解造成这种情况的原因吗?提前致谢。
const Card = (props)=>{
return(
<div style={{margin:'1em'}}>
<img width ="75" src ={props.avatar_url}/>
<div style={{display: 'inline-block', marginLeft: 10}}>
<div style ={{fontSize:'1.25em', fontWeight: 'bold'}}>
{props.name}
</div>
<div>{props.company}</div>
</div>
</div>
);
};
const CardList = (props) => {
return (
<div>
{props.cards.map(card => <Card {...card} />)}
</div>
);
}
class Form extends React.Component {
handleSubmit = (e) => {
e.PreventDefault();
console.log('Event: Form Submit');
};
render() {
return (
<form onSubmit={this.handleSubmit()}>
<input type ="text" placeholder ="Github username"/>
<button type ="submit">Add Card</button>
</form>
);
}
}
class App extends React.Component {
state = {
cards: [
{ name : "Paul O’Shannessy" , avatar_url: "https://avatars1.githubusercontent.com/u/8445?v=4", company: "Facebook" },
{ name : "Ben Alpert" , avatar_url: "https://avatars1.githubusercontent.com/u/6820?v=4",company: "Facebook" },
]
}
render() {
return(
<div>
<Form />
<CardList cards={this.state.cards} />
</div>
);
}
}
ReactDOM.render(<App />,mountNode)