Split React setState
for updating partial state
// in render function ...
const update = splitUpdater(this.setState)
// ...
<input value={value.name} onChange={update('name')}/>
<input value={value.email} onChange={update('email')}/>
<ItemsEditor value={value.items} onChange={update('items')}/>
// ...
// in ItemsEditor ...
const updateItem = splitUpdater(this.props.onChange)
// ...
props.value.forEach((item, index) => {
const update = splitUpdater(updateItem(index))
<input value={item.product} onChange={update('product')}/>
<input value={item.qty} onChange={update('qty')}/>
})
// ...