JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.27k stars 1.11k forks source link

[Web App] How can I add display markup text #1646

Open antranvn opened 2 years ago

antranvn commented 2 years ago

Hello guys, how can I display markup text? Can we use tag or inline style for innerHTML?

koyakei commented 1 week ago
import androidx.compose.runtime.*
import org.jetbrains.compose.web.dom.*
import org.jetbrains.compose.web.renderComposable
import kotlinx.browser.document
import org.w3c.dom.HTMLElement

fun main() {
    renderComposable(rootElementId = "content") {
        Div {
            Button(attrs = {
                onClick {
                    val contentDiv = document.getElementById("content") as HTMLElement
                    contentDiv.innerHTML = "<h1>Hello, Compose Multiplatform!</h1><p>This is an example of using innerHTML.</p>"
                }
            }) {
                Text("Click me")
            }
        }
    }
}

https://www.perplexity.ai/search/Directorybased-routing-routing-lm.u0tF8TPCcx4ErH33k3w#2 Is it ok?