Kevin Worth
03/16/2023, 6:04 PMviewModel()
at the top of a root composable, such as this:
@Composable
fun PrimaryScreen() {
val viewModel: PrimaryViewModel = viewModel()
JokesTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val jokes by viewModel.jokes.collectAsState()
JokeList(
jokes = jokes
)
}
}
}
Initially I put it as a parameter, as seen in this question over in #dagger and it appears I can get around that issue with the above code. So, does anyone see anything less than ideal with the code above? Given viewModel()
is a @Composable
, it seems like it should be fine, yeah?bod
03/16/2023, 6:51 PM