An external library I use exposes a function that ...
# compose-web
s
An external library I use exposes a function that returns an
HTMLDivElement
. My current solution appends this node to the body via
document.body.appendChild(..)
but it feels subpar, and I’d like to know what the alternatives are. Is it possible to take this return value and make a composable of it?
o
yes, it's possible. It's quite similar to integration of the react components into compose-managed-app: https://github.com/JetBrains/compose-jb/blob/master/examples/web-with-react/src/jsMain/kotlin/ReactInComposeApp.kt#L22 in that example, we use DomSideEffect to get the reference to an html element (some kind of a root), and we can call something like:
htmlElement.appendChild(yourLibElement())
👍🏻 1
🙏 3
s
Ah, perfect, thanks a lot. Worked like a charm 😊
🎉 1
s
@Oleksandr Karpovich [JB] any documentation available for
DomSideEffect
and other effects specific to web?
o
@suresh not yet. But it's in progress.
🙏 1