我是 React 和一般编码的新手,我正在尝试构建这个简单的抽认卡应用程序来更好地理解 React。我知道这段代码很糟糕,它可能应该被分解成更多的组件,但我不知道如何向提交按钮添加一个事件处理程序,该按钮将创建一个在一侧具有定义和术语的抽认卡另一方面,它将使它成为,因此当单击该卡时,它将从定义更改为术语。感谢任何反馈,如果这个问题很愚蠢,我提前道歉。
class flashcard extends Component {
constructor(props) {
super(props);
this.state = {
definition: "",
term: "",
};
}
createCard = () => {
this.setState({
definition: "test",
});
};
render() {
return (
<div>
<Navbar bg="primary" variant="dark">
<Navbar.Brand>Flashcard</Navbar.Brand>
<Nav className="mr-auto">
<Button style={this.buttonstyles} variant="outline-light">
Add Card
</Button>
</Nav>
</Navbar>
<Card style={this.styles}>
<Card.Img variant="top" />
<Card.Body>
<Form>
<Form.Group controlId="formBasicEmail">
<Form.Label>definition</Form.Label>
<Form.Control type="definition" placeholder="definition" />
</Form.Group>
<Form.Group controlId="formBasicPassword">
<Form.Label>term</Form.Label>
<Form.Control type="term" placeholder="term" />
</Form.Group>
<Button variant="primary" type="submit" onClick={this.createCard}>
Submit
</Button>
</Form>
</Card.Body>
</Card>
<Button style={this.previoussytle} variant="primary">
Previous
</Button>
<Button style={this.nextsytle} className="m-2" variant="primary">
Next
</Button>
</div>
);
}