Hello hello! I noticed that in Compose, the subDI'...
# kodein
j
Hello hello! I noticed that in Compose, the subDI's output isn't remembered. I can work around it, but shouldn't there be a kind of rememberSubDI out of the box? I have an app where the main page can switch between other pages, which are all sub components of the main component. When the main component recomposes, my subDI's are re-initialized and that is not so nice 🙂
This should do the trick
Copy code
@Composable
fun rememberSubDI(
    diBuilder: DI.MainBuilder.() -> Unit,
    content: @Composable () -> Unit
) {
    val currentDI = localDI()
    val subDI = remember {
        org.kodein.di.subDI(currentDI, false, Copy.NonCached, diBuilder)
    }
    withDI(subDI, content)
}