title: React-Kotlin wrapper setState method
body: <p>On the react docs here:</p>
  
  <p><a href="https://facebook.github.io/react/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous" rel="nofollow noreferrer">https://facebook.github.io/react/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous</a></p>
  
  <p>It says that the following code is unsafe to use because state is updated asynchronously:</p>
  
  <pre><code>this.setState({
    counter: this.state.counter + this.props.increment,
  });
  </code></pre>
  
  <p>And instead to pass in the previous state and props like this:</p>
  
  <pre><code>this.setState(function(prevState, props) {
    return {
      counter: prevState.counter + props.increment
    };
  });
  </code></pre>
  
  <p>However, the React-Kotlin wrapper located here:</p>
  
  <p><a href="https://github.com/Kotlin/kotlin-fullstack-sample/tree/master/frontend/src/org/jetbrains/react" rel="nofollow noreferrer">https://github.com/Kotlin/kotlin-fullstack-sample/tree/master/frontend/src/org/jetbrains/react</a></p>
  
  <p>Has the state change passed in as an extension function of state, which modifies the variables on the state object:</p>
  
  <pre><code>//Located in the ReactComponent class in ReactComponent.kt
  fun setState(builder: S.() -&gt; Unit) {
      ...
  }
  </code></pre>
  
  <p>If I call <code>setState</code> function like this in Kotlin:</p>
  
  <pre><code>setState {
      counter: state.counter + props.increment
  }
  </code></pre>
  
  <p>Isn't that equivalent to the unsafe method above? Wouldn't it need to be implemented like this in the React-Kotlin wrapper?</p>
  
  <pre><code>fun setState(builder: S.(prevState: S, props: P) -&gt; Unit) {
      ...
  }
  </code></pre>
  
  <p>And then called like this?</p>
  
  <pre><code>setState { prevState, props -&gt;
      counter: prevState.counter + props.increment
  }
  </code></pre>