Skip to content

Instantly share code, notes, and snippets.

@CostaFot
Last active February 18, 2026 22:33
Show Gist options
  • Select an option

  • Save CostaFot/6bc53ed85bc001dabd90ba615b49ae50 to your computer and use it in GitHub Desktop.

Select an option

Save CostaFot/6bc53ed85bc001dabd90ba615b49ae50 to your computer and use it in GitHub Desktop.
@Composable
inline fun <reified T : RetainedViewModel> rememberRetainedViewModel(noinline factory: (Context) -> T): T {
val context = LocalContext.current
return retain { factory(context) }
}
// ..compose layer
val customRetainedViewModel = rememberRetainedViewModel { context ->
EntryPoints.get(context, CustomRetainedViewModelEntryPoint::class.java).customRetainedViewModel()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment