I'm using `SnapshotStateList<SnapshotStateList&...
# compose
s
I'm using
SnapshotStateList<SnapshotStateList<MyObject>>
as a state but when I change it, the composables aren't getting recomposed. However, if I wrap it with a mutable state
MutableState<SnapshotStateList<SnapshotStateList<MyObject>>
it's working fine. Is this intended?
Copy code
data class MyStateHolder(
    val name: MutableState<String>,
    val list: SnapshotStateList<SnapshotStateList<MyObject>>
)

var state = remember { MyStateHolder(...) }
...
MyComposable(onSomeEvent = { newList -> state = state.copy(list = newList) })
SomeOtherComposable(state.list) // not getting recomposed when I change state with a new list
I'm not sure but I think it works fine if I just change an item of the list as opposed to copying the whole state for a new list. This works fine:
Copy code
data class MyStateHolder(
    val name: MutableState<String>,
    val list: MutableState<SnapshotStateList<SnapshotStateList<MyObject>>>
)

val state = remember { MyStateHolder(...) }
...
MyComposable(onSomeEvent = { newList -> state.list = newList })
SomeOtherComposable(state.list)
d
Looking at your code, I don't think you need
SnapshotStateList
. Just use
List
and
String
,
Recomposition will only happen when a
State
object changes.
s
I didn't include the whole code but I'd like to do
state.list[i][j] = something
too so I need the SnapshotStateList
d
Oh, in that case just do the latter code snippet.
s
Okay thanks!