I want to render a div component as many times a button is clicked in React JS, what should I use?
The task here was to add multiple input fields when i click the plus button, also can we use for loop here, to render elements ? This is the component I want to render multiple times on button click event:
import React from 'react'
import {Container,Col,Row,Table,Form,FormGroup,Label,Input} from 'reactstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
export default function AddRemoveInputField(prop) {
return (
<div className='smallHr'>
<div className="space"></div>
<div><hr style={{width:
'9rem',margin:'auto'}}/></div>
<div className="space"></div>
<FormGroup row>
<Label
for="exampleText"
sm={2} className='bold padding'
>
Title
</Label>
<Col sm={10}>
<Input onChange={prop.action}
id="exampleText"
name="title"
type="text"
/>
</Col>
</FormGroup>
<FormGroup row>
<Label
for="exampleText"
sm={2} className='bold padding'
>
URL
</Label>
<Col sm={10}>
<Input onChange={prop.action}
id="exampleText"
name="url"
type="text"
/>
</Col>
</FormGroup>
<div className="space"></div>
<FormGroup row>
<Label
for="exampleText"
sm={2} className='bold padding'
>
Discription
</Label>
<Col sm={10}>
<Input
id="exampleText"
name="discription"
type="textarea" onChange={prop.action}
/>
</Col>
</FormGroup>
<div className="space"></div>
<FormGroup row>
<Label className='bold padding'
for="exampleText"
sm={2}
>
Source
</Label>
<Col sm={10}>
<Input onChange={prop.action}
id="exampleText"
name="source"
type="text"
/>
</Col>
</FormGroup>
</div>
)
}```
The Component Looks Like This:
[enter image description here](https://i.stack.imgur.com/XnNmr.png)
I tried using for loop in the Component, but it only rendered it once.
I tried using for loop in the Component, but it only rendered it once.