Ejaz
11/19/2025, 10:55 AMPHondogo
11/19/2025, 11:36 AMCoty Saxman
11/20/2025, 7:25 AMEjaz
11/20/2025, 10:49 AMCoty Saxman
11/20/2025, 3:00 PMdiv in order to act as the host for compose. The created div can be used for anything - in this case, for hosting the compose canvas - and the same method can be used to add other native DOM components. For many of these common components, their basic functionality is built in to compose. If you're using something more complex, you may need to use some raw JS functions, but I'm not yet sure that you'll need them.
import ui.App
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.ComposeViewport
import kotlinx.browser.document
import org.w3c.dom.HTMLDivElement
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid
@OptIn(ExperimentalComposeUiApi::class)
fun main() {
val rootDiv = addDivToBody()
ComposeViewport(viewportContainerId = rootDiv.id) {
App()
}
}
@OptIn(ExperimentalUuidApi::class)
private fun addDivToBody(): HTMLDivElement {
val elementId: String = Uuid.random().toString()
val div = (document.createElement("div") as HTMLDivElement).apply {
id = elementId
classList.add("fullscreen")
document.body?.appendChild(this)
}
return div
}PHondogo
11/20/2025, 3:06 PMEjaz
11/24/2025, 8:56 AMCoty Saxman
11/24/2025, 6:11 PM