Kotlin / kotlin-fullstack-sample

Kotlin Full-stack Application Example
https://kotlinlang.org
Apache License 2.0
1.21k stars 169 forks source link

how to reference a div inside ReactDOMBuilder.render() #14

Closed andrewarrow closed 7 years ago

andrewarrow commented 7 years ago

I've been converting this code:

https://github.com/Kotlin/kotlin-fullstack-sample/blob/master/frontend/src/org/jetbrains/demo/thinkter/HomeView.kt

to my own needs and got to a point where inside the render method I need to do:

val div = document.getElementById("map")
kotlinGoogleMap(div)

this comes from https://blog.frankel.ch/kotlin-front-end-developers/ so the actual line I'm trying to call is line 33 here https://github.com/nfrankel/kotlin-frontend/blob/master/src/script.kt#L33

Is there a good way to do this from my HomeView.kt render method?

andrewarrow commented 7 years ago

I was able to solve this with componentDidMount:

   override fun componentDidMount() {
      super.componentDidMount()
      val div = document.getElementsByClassName("thegmap").item(0)
      kotlinGoogleMap(div)
    }

where render makes the thegmap div:

override fun ReactDOMBuilder.render() {
  div {
    div(classes = "thegmap") {
    }
  }
}