I am using `+onCommit` and it is working perfectl...
# compose
a
I am using
+onCommit
and it is working perfectly fine. But I am unable to understand when
onDispose
is called.
Copy code
var user : User? = null
        // Active type use-case
        +onCommit(1) {
            user = UserAPI.getUserData()
            onDispose {
                UserAPI.letDiscompose() // It contains only println line
            }
        }
m
onDispose is called whenever the composable leaves the composition or the inputs have changed
a
Is there any working example? I am still unable to figure it out.
z
Composables methods that haven't changed are not re-run (recomposed) for efficiency. But once input values to the Composable method have changed, or stuff that you keep inside +state changed, or any other thing currently marked with the unary plus ("effect") has changed, then you really want to update to reflect new values, and invoke the Composable again (recompose). When that happens, you need to "clean up" the previous rendering, that's when onDispose gets called. (Also when the Composable is not updated but removed for good). In my understanding onCommit gets called on every recomposition, while onActive only gets called on the first one (please correct me if I'm wrong).
a
onActive is similar to onCommit when
+onCommit(anyConst)
or
+onCommit(true)
is used. I read somewhere onActive will be removed in future.
👍 1
I am this error while using onCommit
java.lang.IllegalStateException: no stage finishing is allowed while read is disabled
Any one know why ?