I have the following code in a component:
constructor() {
this.state = Immutable.fromJS({
user : {
wasChanged : false,
firstName : false,
lastName : false,
address : {
street : false,
}
}
});
}
onEdit({target: {dataset: {target}}}, value) {
this.setState(function (prevState) {
return prevState.setIn(['user', target], value);
});
}
render() {
var user = this.state.get('user').toJS();
...
}
The problem is that when I try to update the value in onEdit, I see that prevState has a different set of prototypes. I don’t understand why and what I am doing wrong. I see it in the console
> Object.getPrototypeOf(this.state)
src_Map__Map {@@__IMMUTABLE_MAP__@@: true}
> Object.getPrototypeOf(prevState)
Object {}
After the state has been changed, it proceeds to rendering, where of course he cannot find the get function or anything from Immutable
Using the reaction with add-ons 0.13.3.
source
share