I want to feed search terms into a repository to a...
# compose
d
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.
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)
    }
}
Example of the Compose code
r
https://github.com/android/compose-samples/blob/main/Jetsnack/app/src/main/java/com/example/jetsnack/ui/home/search/Search.kt. check official compose sample, you can figure out what to place in your ViewModel by looking into
SearchRepo
and
Search
files
d
Ah ha, I'll take a look 👍 Thanks