is this an bad idea? ```@Composable fun networkSt...
# compose
m
is this an bad idea?
Copy code
@Composable
fun networkState(): State<Boolean> {

    val context = LocalContext.current

    return context.networkStateFlow().collectAsState(initial = false)
}
Actually I'm trying to observe the network state in composables
a
if
context.nextworkStateFlow()
returns a new flow instance each time (and since it looks like an extension function it probably does) you'll want to write that as
Copy code
val context = LocalContext.current
return remember(context) { context.networkStateFlow() }.collectAsState(false)
m
Thank you could you explain why
remember
takes
context
as a parameter?
a
general correctness. If
LocalContext
changes you want to get a new flow for the new context. In practice you probably won't actually see this ever change. But you will see this function recompose from its caller, so you do want to remember the flow.
m
thanks a lot
👍 1