I am very new in ReactJS and I have one question and hope you can help me too solve that one.
My question is: could you help me fix my code in such a way, At the end of each list there is always one empty input field as the last entry. So As soon as someone writes something into the last input field, there is automatically pushed another empty input field to the list and When an input field, which is not the last one, is being emptied during the editing, the entry gets removed.
I tried to first of all create state of array
const [list, setList] = useState([]);
return (
<div className="App">
{list.map((el, i) => {
return (
<List
title={el}
id={i + 1}
handleChange={(e) => setList(...e.target.value, list)}
/>
);
})}
</div>
);
And also I created List component for rendering my inputs
const List = ({ title, id, handleChange }) => {
return (
<div>
{id}
<input onChange={handleChange} value={title} />
</div>
);
};
But I have a bunch of errors, please help me to solve this problem, I will be very thankful for you.