Skip to content

Instantly share code, notes, and snippets.

@thearchetypee
Created April 23, 2023 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thearchetypee/1e651aa9b11378db9f728bf4f1d32e02 to your computer and use it in GitHub Desktop.
Save thearchetypee/1e651aa9b11378db9f728bf4f1d32e02 to your computer and use it in GitHub Desktop.
@Composable
fun MyComponent() {
var data by remember { mutableStateOf("") }
val disposableEffect = remember { mutableStateOf<Disposable?>(null) }
DisposableEffect(Unit) {
val disposable = someAsyncOperation().subscribe {
data = it
}
onDispose {
disposable.dispose()
}
disposableEffect.value = disposable
}
// rest of the composable function
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment