I'm facing something strange in React, and I think that might be possible to do it but I don't know how.
My goal: update a specific attribute of my component state, that can be a nested attribute. But! I want to update it dynamically (working with a onChange call on a bunch of inputs, don't want to code 30 onChange functions, I want to code a generic one).
Example that works:
this.state = { value: 0 }
Then:
var attribute = 'value'
var value = 'myvalue'
this.setState({[attribute]:value})
Example that does not work:
this.state = { nested: { value: 0 } }
Then:
var attribute = 'nested.value'
var value = 'myvalue'
this.setState({[attribute]:value})
I can have potentially as many nesting levels as possible. I want to find a generic and easy to afford method to deal with it.
I created a JSFiddle wich reproduces this problem as I'm trying to implement it, with onchange function: http://jsfiddle.net/n61kv6gy/
Does anyone has an idea?