In React assuming I have an integer variable called myProperty which is returned from getDafaultProps, if I console.log(myProperty) before and after I call this.setProps(myProperty+1) in a update function the console logs the same value for myProperty.The property updates after the function ends and next time I called my function myProperty is the new value but does anyone know why or rather explain to me why myProperty is not updated immediately when this.setProps is called?
thanks for taking your time to respond. relevant code below
getDefaultProps: function() {
return { colorIndex: -1 };
},
update: function() {
console.log("clicked and index is " + this.props.colorIndex); //returns -1
this.setProps({colorIndex: this.props.colorIndex + 1});
console.log("index is now " + this.props.colorIndex); /still returns -1
},