Vlad Cipariu
06/29/2025, 9:13 PMorg.jetbrains.androidx.lifecycle:lifecycle-viewmodel
. This worked with WASM but because of the issues mentioned above (you can't copy paste either) when I tried to run with JS and then it started crashing when trying to deploy I get this exception:
IllegalStateException: No ViewModelStoreOwner was provided via LocalViewModelStoreOwner
I am aware that web doesn't support reflection so my view model is provided by something like this: viewModel { MyViewModel() }
. I've been wracking my brain trying to figure out if KMP can offer a complete web experience or should I go with something else for this task alone? (Android and iOS work nicely)
Thank you for you time!Vlad Cipariu
06/29/2025, 9:43 PMfun main() {
renderComposable(rootElementId = "root") {
// Provide explicit initializer: required on non-JVM targets :contentReference[oaicite:3]{index=3}
val vm: CounterViewModel = viewModel { CounterViewModel() }
val count = vm.count.collectAsState()
Div {
Button(
attrs = {
onClick { vm.increment() }
}
) {
"Clicked ${count.value} times"
}
}
}
}
class CounterViewModel : ViewModel() {
private val _count = MutableStateFlow(0)
val count: StateFlow<Int> = _count
fun increment() {
viewModelScope.launch {
_count.value += 1
}
}
}
this results in the same exception
IllegalStateException: No ViewModelStoreOwner was provided via LocalViewModelStoreOwner
Artem Kobzar
06/30/2025, 6:24 AMVlad Cipariu
06/30/2025, 8:07 AMOleksandr Karpovich [JB]
07/01/2025, 8:48 AMLocalViewModelStoreOwner
:
LocalViewModelStoreOwner.provides(...)
Vlad Cipariu
07/01/2025, 8:57 AMOleksandr Karpovich [JB]
07/01/2025, 8:59 AMthen it asked to provide the local densitiesgot it 🙂 you probably trying the untravelled path, which might lead to something interesting and useful