Is it ok to set state type as a lambda? (`MutableState<(() -> Unit)?>`) I've been thinking...
b
Is it ok to set state type as a lambda? (
MutableState<(() -> Unit)?>
) I've been thinking about doing some kind of "confirmation dialog decorator" (confirmation or other, e.g. "request pin") for some user actions. It would be used like
Copy code
var confirmationDialog: (() -> Unit)? by remember {
    mutableStateOf(null)
}

if (confirmationDialog != null) {

    Dialog(onOk = {
        confirmationDialog?.invoke()
        confirmationDialog = null
    }, onCancel = {
        confirmationDialog = null
    })
}

SaveButton(
  onClick = requireConfirmation { theRealSave() }
)
Is it too hacky? Any issue other issue?
z
yea that’s fine, you can always create a type alias or fun interface if you find the function type to be too cryptic
b
thanks. it works, but feels strange.
l
It's perfectly fine to put lambdas in
MutableState
, that's how I bridge coroutines reliant UI abstractions with state driven composables.