I have this layout
DESIRED BEHAVIOUR
In the start there is only one input. First one. And it is empty. When i type something in it and press 'ADD +' new input under that one is created , it is disabled and it has value of first one that I was typing in. First one is then cleared and it is empty again. I really have no idea how to make this.
This is the code that I currently have.
const FilterListInput = ({ data }) => {
const [comp, setComp] = useState('');
const [rows, setRows] = useState([[]]);
console.log(rows);
const handleChange = (e, index) => {
rows[index] = e.target.value;
setRows(rows);
};
return (
<>
<div className="filter__form__elements__element">
<label htmlFor={data.name}>{data.labelName}</label>
<For
of={rows}
render={(item, index) => (
<>
<Input
name={item.name}
placeholder={data.placeholder}
onChange={(e) => handleChange(e, index)}
/>
</>
)}
/>
</div>
<Button title="ADD +" type="secondary" onClick={() => setRows([...rows, comp])} />
</>
);
};
I am stuck here and I have no idea where to go next. Currently when I create new input I can type in it and data from the first one is left in it which I don't want. Also I want everything to be saved in rows hook.
I am not asking for full code. Just some guidlines.
Thank you in advance
