The code below is a minimal repro of code setting a ref. I was a bit surprised that most of the ttime it prints null but sometimes the actual div. I expected it to be always not null:
@JSExportTopLevel("ReproMain")
object ReproMain {
val component =
ScalaFnComponent
.withHooks[Unit]
.useRefToAnyVdom
.render { (_, ref) =>
// val r = <.div(^.untypedRef := ref, "Test")
val r = <.div("Test").withRef(ref)
println(s"cur ${ref.raw.current}")
r
}
@JSExport
def main(): Unit = {
val container = Option(dom.document.getElementById("root")).getOrElse {
val elem = dom.document.createElement("div")
elem.id = "root"
dom.document.body.appendChild(elem)
elem
}
component().renderIntoDOM(container)
()
}
}
I need access to current to integrate with a third-party library
The code below is a minimal repro of code setting a ref. I was a bit surprised that most of the ttime it prints null but sometimes the actual div. I expected it to be always not null:
I need access to current to integrate with a third-party library