than_
03/08/2021, 3:41 PMViewModel
and collectAsState
but by doing that I lost the ability to change state in the interactive mode in android studio. Is there something I'm missing?Zach Klippenstein (he/him) [MOD]
03/08/2021, 4:50 PMthan_
03/08/2021, 5:10 PMZach Klippenstein (he/him) [MOD]
03/08/2021, 5:32 PMthan_
03/08/2021, 6:49 PMthan_
03/08/2021, 6:49 PMthan_
03/08/2021, 6:50 PMZach Klippenstein (he/him) [MOD]
03/08/2021, 7:06 PMthan_
03/08/2021, 7:59 PMval (stt, dispatch) = remember { reducerStateOf(1, ::reducer) }
Zach Klippenstein (he/him) [MOD]
03/08/2021, 8:09 PMState<STATE>
in that pair? Right now you’re just returning the initial state value as the raw value, which means it has no way to be updated after being memoized by remember
Zach Klippenstein (he/him) [MOD]
03/08/2021, 8:10 PMfun <ACTION, STATE> reducerStateOf(initialValue: STATE, reducer: Reducer<ACTION, STATE>): Pair<State<STATE>, Dispatch<ACTION>> {
val state = mutableStateOf(initialValue)
val dispatch: Dispatch<ACTION> = {action: ACTION ->
val newState = reducer(action, state.value)
state.value = newState
}
return state to dispatch
}
Zach Klippenstein (he/him) [MOD]
03/08/2021, 8:11 PMthan_
03/08/2021, 9:21 PM