Last active
June 9, 2022 12:07
-
-
Save sadam1807/baa04b0594dab608001b2b51f29880b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react' | |
const App = () => { | |
const [formValues, setFormValues] = useState([{ name: "", email : ""}]) | |
return ( | |
<form onSubmit={handleSubmit}> | |
{formValues.map((element, index) => ( | |
<div className="form-inline" key={index}> | |
<label>Name</label> | |
<input type="text" name="name" value={element.name || ""} onChange={e => handleChange(index, e)} /> | |
<label>Email</label> | |
<input type="text" name="email" value={element.email || ""} onChange={e => handleChange(index, e)} /> | |
{ | |
index ? | |
<button type="button" className="button remove" onClick={() => removeFormFields(index)}>Remove</button> | |
: null | |
} | |
</div> | |
))} | |
<div className="button-section"> | |
<button className="button add" type="button" onClick={() => addFormFields()}>Add</button> | |
<button className="button submit" type="submit">Submit</button> | |
</div> | |
</form> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hcfhdfhdfhdfdfgdf