https://kotlinlang.org logo
Title
c

Chris Miller

04/17/2023, 6:30 PM
I have a Compose for Web project (now called compose-html I believe? Very confusing...), and I have a component that I want to recompose when window.innerWidth changes. Is the right way to do this via window.addEventListener("resize", { ... }), or is there a better approach?
d

Dima Avdeev

04/17/2023, 6:36 PM
Yes, stable Compose for Web is now called Compose HTML. It's because the new Compose Web is experimental and can share a lot of code with Desktop, Android and iOS.
Yes, you can use any JS API inside Compose for that purpose.
One of the places you can write this logic is DisposableEffect() { ... }
c

Chris Miller

04/17/2023, 6:40 PM
Thanks. It might be helpful to have something about Compose HTML on the https://www.jetbrains.com/lp/compose-multiplatform/ page - it's quite confusing to see various old blog posts referencing Compose for Web, and them being at odds with the new official page but without any obvious explanation of what's going on
OK thanks, I'll do as you suggest. I was half wondering if the recompose should be triggered automatically on a resize but I guess not
d

Dima Avdeev

04/17/2023, 6:41 PM
Yeah, thanks, we have similar feedback about misunderstanding about Compose HTML and Compose Web
DisposableEffect - is one of API to add event subscription to external changes. It may be used in all platforms to handle a platform changes (JS DOM for your case).
c

Chris Miller

04/17/2023, 6:47 PM
Ok great, thanks for the pointers!
m

Morten Minke

04/17/2023, 7:15 PM
I struggled with the same information confusion and therefor started the creation of a material design 3 component library. However, I now wonder if this is the right thing to do if all developments actually move towards the non-html code with reuse for multiplatform. Mmm, I guess time will tell, for now I will continue using the html+md3 approach and see if I run into a dead-end. I am still enthousiastic about being able to use kotlin for the front-end!
c

Chris Miller

04/17/2023, 8:47 PM
For my current case I'm just making a pretty simple website and prefer to go with Compose HTML instead of a canvas based solution like the new Compose Web. That said, it's much more pleasant to develop UIs with Jetpack Compose / Compose Desktop than anything HTML/CSS related