How to access SnapshotStateList size in Kotlin Compose?

52 views Asked by At

How am I able to use the SnapshotStateList.size properly without causing an infinite loop of (I assume) recompositions? Based on other questions/answers it is most likely due to reading the list value and that read operation causes a recomposition... There doesn't seem to be anything about how to then find and use those read-only values, either directly or by other means.

Basically I am trying to use an if-else statement to make a composable visible, as long as there are already items within the list.

Below is heavily simplified

val list = remember {
  mutableStateListOf<String>()
}

/* update list */

if (list.size != 0) {
  /* add composables */
}

Whether I use .size or .isEmpty() I still get an infinite loop occurring.

I assume that I must convert this list into some other sort of list, but I haven't been successful in getting that to work either. toList() or toMutableList() haven't worked properly either. My intent was to work around the read operation in order to get the correct size value.

Thank you for any help/support that you can provide.

0

There are 0 answers