Also in React (non-Kotlin) `SetState(JSobject, fun...
# react
r
Also in React (non-Kotlin)
SetState(JSobject, function(){callBack code})
is as @Filipp Riabchun said the state is batched and asynchronous. Meaning that the state change isn't immediate and in JS React if you need to have some action occur when the state actually changes you include a call back function as the second argument. I'm not sure how Kotlin transpiles the JS for this.
f
You can actually do it like that in Kotlin:
Copy code
setState(jsObject {
  // type is infered
  foo = "bar"
}) {
  // your callback
}
Or like that, if you need to use previous state values:
Copy code
setState ({
  jsObject {
    bar = it.bar + 1
  }
}) {
  // your callback
}