Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package com.babylonhealth.ember.ui
import scala.concurrent.Future
import org.scalajs.dom.console
import org.scalajs.dom.ext.Ajax
import slinky.core.Component
import slinky.core.annotations.react
import slinky.web.html.div
// Example of weird setSate, the console prints:
// onComplete: isCompleted: true
// Render: isCompleted: false
@react class MyComponent extends Component {
type Props = Unit
case class State(foo: Option[Future[String]])
def initialState = State(None)
def render = { match {
case Some(f) =>"Render: isCompleted: ${f.isCompleted}")
case None =>
override def componentDidMount(): Unit = {"Did mount")
val f: Future[String] = Ajax.get("").map(_ => "abc")
f.onComplete(result => {
assert(f.isCompleted)"onComplete: isCompleted: ${f.isCompleted}")
setState(State(foo = Some(f)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.