I have a DisposableEffect which registers an eventlistener, and disposes of it again. But it appears that I am not allowed to update MutableState variables inside this event listener? I get compiler errors:
Copy code
var editMode by remember { mutableStateOf(false) }
DisposableEffect(Unit) {
val handler : EventListener = object : EventListener {
override fun handleEvent(event: Event) {
if (event.target != null) {
//editMode = false <- compiler error when I uncomment this
}
}
}
document.body?.addEventListener("click", handler)
onDispose {
document.body?.removeEventListener("click", handler)
}
}
And the last part of the stack-trace:
Copy code
java.lang.IllegalStateException: Validation failed in file Components.kt
at org.jetbrains.kotlin.backend.common.IrValidator.error(IrValidator.kt:83)
at org.jetbrains.kotlin.backend.common.IrValidator.access$error(IrValidator.kt:61)
EDIT: It appears to work when using a lambda function as argument to the eventListener and not an object.
s
shikasd
07/08/2022, 4:21 PM
Seems like a compiler bug to me, probably worth reporting to the GitHub repo