In the web app that I'm working on, I'm giving the user an option to select the number of machines they have inside a facility. Based on the selected number, a respective number of form fields appear to the user. I managed to configure the interface using this question here. I'm confused now on how to read the input values of each field into a dynamic state array? this is the code that I'm working on currently JSFiddle.
handleOnChange(value) {
this.setState({ inputSize: value.target.value });
}
renderInputs(value) {
const inputs = [];
for (let i = 0; i < value; i++) {
inputs.push(
<div>
<Input
value={this.state.sortingMachines[i]}
onChange={(event) =>
this.props.setState({ sortingMachines: event.target.value })
}
icon="ethereum"
/>
</div>
);
for (let i = 0; i < value; i++) {
console.log(this.state.sortingMachines[i]);
}
}
return inputs;
}
render() {
const { sortingMachines } = this.state;
console.log(this.state.inputSize);
return (
<div>
<Form.Field width={6}>
<label>Sorting Machines Address</label>
<input
type="number"
name="quantity"
min="1"
max="7"
onChange={(value) => this.handleOnChange(value)}
/>
<div>{this.renderInputs(this.state.inputSize)}</div>
</Form.Field>
</div>
);
}
ReactDOM.render(<Hello name="World" />, document.getElementById("container"));