Hi, is it safe to remember current context, and us...
# compose-android
k
Hi, is it safe to remember current context, and use it to launch some things dependent on that context?
Copy code
@Composable
fun rememberX(context = LocalContexxt.current) = remember { DataClass(context = contexxt) }

@Composable
fun Sample() {
  val x = rememberX()
  Button(text = "test", onClick = { // do something with context via x.context })
}
j
it should be fine, in most (if not all) cases the remember will live "shorter" then the context itself i think. If you want to be safe you can do
remember(context) { DataClass(context = context) }
. This way if context changes - the DataClass will be recreated