Thread
#compose-web
    Arjan van Wieringen

    Arjan van Wieringen

    2 months ago
    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:
    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:
    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.
    shikasd

    shikasd

    2 months ago
    Seems like a compiler bug to me, probably worth reporting to the GitHub repo
    Arjan van Wieringen

    Arjan van Wieringen

    2 months ago
    Yes, I will do that