Skip to content

Instantly share code, notes, and snippets.

@skydoves
Last active August 9, 2024 04:34
Show Gist options
  • Select an option

  • Save skydoves/90cebd97fd4178946e357284afccaed5 to your computer and use it in GitHub Desktop.

Select an option

Save skydoves/90cebd97fd4178946e357284afccaed5 to your computer and use it in GitHub Desktop.
user_viewmodel
public class UserViewModel: ViewModel() {
private var mutableUsers = mutableStateListOf<User>()
internal val users: StateFlow<List<User>> = MutableStateFlow(mutableUsers)
}
@Composable
fun UserProfiles(viewModel: UserViewModel) {
val users by viewModel.users.collectAsStateWithLifecycle()
LazyColumn {
items(users) { user ->
..
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment