Reputation: 645
I'm creating form where user can add documents. Each document have 6 inputs (select, text input, date input, file input). User can add as much as he want documents, for example: some users need to add 4 documents, some - 20 and more.
So I'm trying to figure out how to get values from all inputs, when I can't to set values to states.
I'm using Material UI, maybe is there easy way to get values?
Upvotes: 1
Views: 105
Reputation: 1413
This is called a controlled input
To make this dynamic you could set state as an object then just setState adding keys as you need them
const [inputValues, setInputValues] = useState({});
...
const handleChange = (inputId) => (e) => setInputValues({ ...inputValues, [inputId] : e.target.value })
...
<input value={inputValues[inputId]} onChange{handleChange(inputId)} />
Upvotes: 1