useFlowBinding

fun <T> ComponentScope.useFlowBinding(flow: StateFlow<T>): DynamicValue<T>

Creates a DynamicValue that is bound to a StateFlow. The DynamicValue will automatically update whenever the StateFlow emits a new value, enabling reactive UI updates without triggering component re-renders.

This is useful for binding external state sources (like ViewModels or use cases) to Litho's animated properties such as Style.alpha, enabling smooth transitions driven by StateFlow emissions.

Example usage:

class MyComponent(private val alphaFlow: StateFlow<Float>) : KComponent() {
override fun ComponentScope.render(): Component {
val alpha = useFlowBinding(alphaFlow)
return Row(style = Style.alpha(alpha)) { ... }
}
}

Return

A DynamicValue that updates whenever the flow emits a new value.

Parameters

flow

The StateFlow to bind to. The initial value of the DynamicValue will be the current value of the flow.