Using Redux
State
data class MyState(val content: String, val counter: Int)Actions
sealed class MyAction : RAction {
object Increment : MyAction()
object Decrement : MyAction()
data class SetContent(val content: String) : MyAction()
}Reducer function
fun myReducer(state: MyState, action: MyAction): MyState = when (action) {
is MyAction.Increment -> {
state.copy(counter = state.counter + 1)
}
is MyAction.Decrement -> {
state.copy(counter = state.counter - 1)
}
is MyAction.SetContent -> {
state.copy(content = action.content)
}
}Store
Dispatching actions
Subscribing to the store
State binding
Last updated