
Integrates Compose Multiplatform with Redux architecture, facilitating state management and UI updates through a reducer-based approach. Simplifies creating and dispatching actions within composable functions.
Compose Multiplatform integration for Redux Kotlin
Artifacts are hosted on maven central. For multiplatform, add the following to your shared module:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("org.reduxkotlin:redux-kotlin-compose:_")
}
}
}
}For JVM only:
dependencies {
implementation("org.reduxkotlin:redux-kotlin-compose-jvm:_")
}data class State(val name: String? = null)
sealed interface Action {
data class Rename(val name: String) : Action
object ClearName : Action
}
val reducer: Reducer<State> = reducerForActionType<State, Action> { state, action ->
when (action) {
is Action.Rename -> state.copy(name = action.name)
is Action.ClearName -> state.copy(name = null)
}
}
@Composable
fun App() {
StoreProvider(createStore(reducer, State())) {
Component()
}
}
@Composable
fun Component() {
val name by selectState<State, String> { name }
val dispatch = rememberDispatcher()
Text(name)
Button(
text = "Clear",
onClick = {
dispatch(ClearName)
}
)
}
Compose Multiplatform integration for Redux Kotlin
Artifacts are hosted on maven central. For multiplatform, add the following to your shared module:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("org.reduxkotlin:redux-kotlin-compose:_")
}
}
}
}For JVM only:
dependencies {
implementation("org.reduxkotlin:redux-kotlin-compose-jvm:_")
}data class State(val name: String? = null)
sealed interface Action {
data class Rename(val name: String) : Action
object ClearName : Action
}
val reducer: Reducer<State> = reducerForActionType<State, Action> { state, action ->
when (action) {
is Action.Rename -> state.copy(name = action.name)
is Action.ClearName -> state.copy(name = null)
}
}
@Composable
fun App() {
StoreProvider(createStore(reducer, State())) {
Component()
}
}
@Composable
fun Component() {
val name by selectState<State, String> { name }
val dispatch = rememberDispatcher()
Text(name)
Button(
text = "Clear",
onClick = {
dispatch(ClearName)
}
)
}