Thread
#compose-web
    v

    Vinay Gaba

    1 year ago
    Does Compose for Web have an interoperability story that's as compelling as Compose for Android i.e can I leverage Compose for Web in an existing React website? If yes, any examples I can check? I think incremental adoption would be super powerful and I have a feeling that its most likely supported or at least on the roadmap?
    cc @louiscad who just asked me a related question that got me thinking about this 😄
    shikasd

    shikasd

    1 year ago
    I think JB provided some examples with React interop here: https://github.com/JetBrains/compose-jb/tree/master/examples/web-with-react, not sure if you are looking for something more involved or not 😃
    jim

    jim

    1 year ago
    Also, Compose for Web will just compose into a DOM node, so you can take pretty much any DOM node and render your Compose tree inside it.
    v

    Vinay Gaba

    1 year ago
    that's fantastic! As a follow up, does this require me to leverage kotlinx.html first? Can I use my pure vanilla React app and still use Compose for building some of the components (if I wanted to)
    shikasd

    shikasd

    1 year ago
    Kotlinx.html is completely unrelated here, I think, it is just a dsl for building html 😃 Compose allows to render Composables into any dom node, so you can just grab a ref from React component, and use it as a root for Compose.
    v

    Vinay Gaba

    1 year ago
    Interesting! Thinking about how I can introduce it in a React codebase. Like how do I include it within a project that uses npm for dependency management.
    louiscad

    louiscad

    1 year ago
    Maybe you can try creating a Kotlin/JS project, and include your existing React code into it instead?
    shikasd

    shikasd

    1 year ago
    I think it would require some clever interfacing to expose proper methods to JS + somehow merge webpack/(name your bundler) configuration to build and include Kotlin/JS bundle
    louiscad

    louiscad

    1 year ago
    @Sebastian Aigner If you're looking at helping folks doing Kotlin for the browser, I think that for a starter, an example of adding Kotlin/JS to an existing React project would be very helpful.
    hfhbd

    hfhbd

    1 year ago
    louiscad

    louiscad

    1 year ago
    Integrating with a non Kotlin project, with no plans to rewrite the React code to Kotlin.
    hfhbd

    hfhbd

    1 year ago
    Ahh, okay.
    a

    Akif Abasov [JB]

    1 year ago
    @louiscad, you don’t need to rewrite it in Kotlin, you just need to write some
    external
    declarations to make it possible to call js react components from Kotlin.https://kotlinlang.org/docs/js-interop.html#external-modifier And looks like it is used in example above:https://github.com/JetBrains/compose-jb/blob/master/examples/web-with-react/src/jsMain/kotlin/ReactYoutubePlayer.kt