A composable with a navhost is recomposing in an i...
# compose
p
A composable with a navhost is recomposing in an infinite loop if I add an if condition to navigate to a screen if a int parameter representing the current section has been changed. The condition has not changed, the parameter is always 1, but the composable is being recomposed constantly if I add that if. Anyone can explain me that?
Copy code
if (currentSectionId != startSection.toInt()){
        navController.navigate(currentSectionId.toString())
        Log.d("XXXX", "new section: $currentSectionId")
    }
the full composable:
Copy code
@Composable
fun ApplicationNavHost(
    currentSectionId: Int,
    modifier: Modifier = Modifier,
    navController: NavHostController = rememberNavController()
) {
    val sections = SectionHolder.sections
    val startSection = SectionHolder.startSection

    NavHost(
        navController = navController,
        startDestination = startSection.toString(),
        modifier = modifier
    ) {
        for ((i, section) in sections.withIndex()) {
            Log.d("XXXX", "added route: $i")
            composable(route = i.toString()) {
                SectionComposableFactory(
                    section = section,
                )
            }
        }
    }

    if (currentSectionId != startSection.toInt()){
        navController.navigate(currentSectionId.toString())
        Log.d("XXXX", "new section: $currentSectionId")
    }
}