Closed grassick closed 8 years ago
class ChangeOnMount extends React.Component
componentWillMount: ->
val = {}
val[@props.k] = @props.v
@props.onChange(_.extend({}, @props.value, val))
render: ->
H.div null,
JSON.stringify(@props.value)
class ChangeOnMountParent extends React.Component
constructor: ->
@state = {
value: { test: 0 }
}
handleChange: (value) =>
console.log "handleChange: " + JSON.stringify(value)
@setState(value: value)
render: ->
console.log JSON.stringify(@state.value)
H.div null,
R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "a", v: 1
R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "b", v: 2
R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "c", v: 3
R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "d", v: 4
{"test":0,"d":4}
{"test":0,"d":4}
{"test":0,"d":4}
{"test":0,"d":4}
So no, but:
_.defer () =>
val = {}
val[@props.k] = @props.v
@props.onChange(_.extend({}, @props.value, val))
does work.
Problem is there are 4 setstates at beginning and no re-render until later. Will affect how we handle the "remove all answers that are invisible" problem. Should be done at top level, perhaps?
What happens in a large immutable structure where multiple component modify it on mount?