Skip to content

reduxkotlin/redux-kotlin-compose

This branch is 1 commit ahead of master.

Folders and files

NameName
Last commit message
Last commit date
Sep 3, 2024
Feb 2, 2023
Feb 2, 2023
Jan 13, 2023
Feb 2, 2023
Feb 2, 2023
Aug 8, 2022
Feb 2, 2023
Feb 2, 2023
Jan 17, 2023
Feb 2, 2023
Feb 2, 2023
Aug 8, 2022
Aug 8, 2022
Jan 17, 2023
Feb 2, 2023

Repository files navigation

Releasebadge badge badge Slack chat Dokka docs Version maven-central Version maven-snapshot

Redux-Kotlin-Compose

Compose Multiplatform integration for Redux Kotlin

Installation

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:_")
}

Usage

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)
    }
  )
}