Hey guys, has anyone worked with SnapshotStateMap ...
# compose-android
a
Hey guys, has anyone worked with SnapshotStateMap and LazyColumn? If yes, how do you approach search implementation using snapshotstatemap? If we use two mutable states, we can use combine and achieve search and filter a list. But in snapshotstatemap, it is not possible. Also, if we manually store a copy and implement it, there are unwanted recreation and recomposition of items. Did anyone face this? Let me know if there are any alternatives. Thanks.
z
If you have something like
Copy code
var query by remember { mutableStateOf(“”) }
val stateMap = remember { mutableStateMapOf() }
You could do something like
Copy code
val searchResults by remember(stateMap) {
  snapshotFlow {
    stateMap.filter { isMatch(it, query) }
  }
}.collectAsState()
f
That's an interesting pattern with
remember { snapshotFlow {} }.collectAsState()
. Is the only difference to derived state the fact that you have to be in composition to get a State? 🤔
z
Good catch, just checking to see if anyone else was awake 😅 😅 😅 I don’t know why I suggested using
snapshotFlow
on Tuesday, maybe I misread the original message.
derivedStateOf
is clearly the better solution here.
But no, you could also use dso outside of composition.