react dynamic inputs with id

The solution for “react dynamic inputs with id” can be found here. The following code will assist you in solving the problem.

import React from ‘react’;
import { useState } from ‘react’;

function DynamicInput() {

const [values, setValues] = useState({ val: []});

function createInputs() {
return values.val.map((el, i) =>


);
}

function handleChange(event) {
let vals = […values.val];
vals[this] = event.target.value;
setValues({ val: vals });
}

const addClick = () => {
setValues({ val: […values.val, ”]})
}

const removeClick = () => {
let vals = […values.val];
vals.splice(this,1);
setValues({ val: vals });
}

const handleSubmit = event => {
alert(‘A name was submitted: ‘ + values.val.join(‘, ‘));
event.preventDefault();
}

return (

{createInputs()}


);

}

export default DynamicInput;

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in