我有以下代码的问题
export class MultipleInput extends React.Component {
constructor(props) {
super(props);
this.state = {
rowCount: 1
};
}
addRow = () => this.setState({ rowCount: this.state.rowCount + 1 });
deleteRow = () => this.setState({ rowCount: this.state.rowCount - 1 });
renderRow = i => {
const { type, value } = this.props;
const { rowCount } = this.state;
return (
<div>
<input type={type} value={value} />
<button onClick={this.addRow}>add</button>
{i > 0 && <button onClick={this.deleteRow}>delete</button>}
</div>
);
};
render() {
const { rowCount } = this.state;
return <div>{times(rowCount, this.renderRow)}
<br /><br />
problems
<p>when there is more input, says i enter something in the input, fill something, then click remove, the value is filled in other value</p>
</div>
}
}
要重现单击添加,请在第二个输入中填写一些值,然后单击第二行的删除,输入的值在那里。