Skip to content

observeProperty

@Composable



inline fun <T> observeProperty(propertyName: String, initialValue: T? = null): MutableState<T?>

Observes a property on the block entity in the current composition context.

Returns a MutableState that automatically triggers recomposition when the property changes. Must be called where LocalBlockEntityState has been provided (e.g. inside a block entity's screen composition) — otherwise it throws.

Example

@Composable
fun MyComponent() {
    val powerState = observeProperty<Int>("power")
    Text("Power: ${powerState.value}")
}

Return

A MutableState of type T reflecting the property's current value.

Parameters

  • propertyName: The name of the property to observe.

  • T: The expected type of the property.

Throws

RuntimeException

if no ComposeBlockEntityState is available in the current composition.