I want to feed search terms into a repository to asynchronous get a list of items, which in turn will be displayed in a LazyColumn. What is the best way to do that with MutableState? Ideally I want to place a debounce in the ViewModel and have that regulate calls to the repository. If I had a LiveData, I would have used a switchMap, for example, observing changes on the search term.
David Edwards
05/26/2021, 11:50 AM
Copy code
@Composable
fun SearchScreen() {
val model by viewModel<SearchViewModel>()
var searchTerm by remember { model.term }
val searchResults by remember { model.searchResults }
Column(
modifier = Modifier
.fillMaxSize(),
) {
TextField(
modifier = Modifier.fillMaxWidth(),
value = searchTerm,
onValueChange = {
searchTerm = it
}
)
SearchList(list = searchResults)
}
}