UNPKG

react-jam-ui

Version:

React JAM UI components

22 lines (20 loc) 547 B
export default function(e) { const key = e.target.name; const target = e.target const value = target.type === 'checkbox' ? target.checked : target.value; const keys = key.split('.'); const field = keys[0]; keys.shift(); const result = keys.length ? this.state[field] : value; let tmp = result; keys.forEach((f, i) => { if (i == keys.length - 1) { tmp[f] = value } else { tmp = tmp[f] || {} } }) this.setState({ [field]: result }); }