我想根据用户输入渲染组件的次数。例如,我有一个问题,询问您要创建多少个框,旁边有一个文本框,您可以在其中提交一个数字。无论该数字是多少,我都想在屏幕上渲染该框的次数(假设我在另一个文件中创建了一个框)。我该怎么做呢?我是在我的 Box.js 文件(如下)还是我的组件所在的 App.js 文件中执行此操作?我需要一个简单而详细的解释,因为我是 React 新手。
我使用 Bootstrap React 的代码:
const Box = (props) => {
return (
<div>
<Col xs={12} sm={8} md={8} lg={8} smOffset={2} mdOffset={2} lgOffset={2} >
<Panel bsClass="panel">
<Form horizontal>
<Row>
<Col componentClass={ControlLabel} lg={6}>
How many boxes do you want to create?
</Col>
<Col lg={4}>
<FormControl placeholder="Enter a number..." />
</Col>
<Col lg={2}>
<Button type="submit">
<FaArrowRight style={arrowStyle} />
</Button>
</Col>
</Row>
</Form>
</Panel>
</Col>
</div>
)
};