Readme Index
- Installation
- StoreFlow Core Api
- SideEffects
- Subscriber Aware StoreFlow
- Jetpack Compose Support
- Unit Test Support
Jetpack Compose Support
Module: com.episode6.redux:compose:1.1.7-SNAPSHOT
The :compose module includes a StoreFlow.collectAsState() convenience method for use in Jetpack Compose (both android and kotlin multi-platform). This removes the need for the caller to specify a default value, since a StoreFlow includes a stable initialValue that is used. We also include a version of the method that takes a transform lambda as a parameter, to collect only part of the State.
Note: Since Kotlin 2.x, the Compose Compiler is integrated into the Kotlin compiler. To use Compose, ensure the Compose plugin is applied in your build.gradle.kts:
plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.4.0"
}
Example:
@Composable fun storeFlowExample(store: StoreFlow<TrafficLightState>) {
// collect the entire state
val entireState: TrafficLightState by store.collectAsState()
// only collect a part of the state
val greenLight: Boolean by store.collectAsState { it.green }
}