Would it be bad to call `viewModel()` at the top o...
# compose
k
Would it be bad to call
viewModel()
at the top of a root composable, such as this:
Copy code
@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?
b