import React, {Component, PropTypes} from 'react' import DebouncingInput from './DebouncingInput' class KeyValueEditor extends Component { _addField () { console.log('_addField'); this.props.onChange([...this.props.pairs, {name: '', value: ''}]); } _onChangeName (position, name) { this.props.onChange( this.props.pairs.map((p, i) => i == position ? Object.assign({}, p, {name}) : p) ); } render () { const {pairs} = this.props; return (
{pairs.map((pair, i) => (
this._onChangeName(i, name)} debounceMillis={300} autoFocus={!pair.name}/>
))}
) } } KeyValueEditor.propTypes = { onChange: PropTypes.func.isRequired, pairs: PropTypes.array.isRequired }; export default KeyValueEditor;