Hey everyone, I’ve been migrating our project from...
# javascript
j
Hey everyone, I’ve been migrating our project from
kotlin-react-legacy
to
kotlin-react
and I got a question about injecting the react app into the dom. For example we have something like: main.kt
Copy code
import react.FC
import react.create
import react.dom.client.createRoot
import web.dom.document

fun main() {
  createRoot(document.getElementById("root")!!).render(App.create())
}

private val App = FC {
  +"Hello, world!"
}
index.html
Copy code
<html>
 ...
 <body>
  <div id="root"></div>
 <body>
</html>
Here
web.domdocument.getElementById(...)
and even
document.body
returns null, unless i wrap it in a
window.onload
is this correct? Seems counter whats in the usage guide so just wondering what I’m missing here?
Copy code
kotlinReactVersion=18.3.1-pre.799

implementation("org.jetbrains.kotlin-wrappers:kotlin-react:$kotlinReactVersion")
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:$kotlinReactVersion")
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-router-dom:$kotlinReactRouterVersion")
t
Probably it would be easier to create container yourself 😉
j
Yeah i tried that however
document.body
is null unless i wrap the whole thing in a
window.onload
t
Are your app inside iframe?
j
They are not
t
JFYI - we have Version Catalog with strict accessors 🙂
j
Awesome that fixed it! Thank you for the help
And good to know, we’ll have to pull that in as well