Hi, i using a model class like this SomeClass( v...
# compose
s
Hi, i using a model class like this SomeClass( var badge: MutableState<Badge?> ...... ) But when i trying to update the badge property it Recompose even if the Badge Object is same.
t
how are you updating badge?
make sure you're updating
badge.value
and not the
badge
MutableState
instance. might be easier to use property delegates and write it as
var badge by mutableStateOf<Badge?>
instead so that you can read/write to it as a regular
var
.
s
I'm updating it like this
Copy code
pack.badgeText = OPEN(context.getString(R.string.open))
z
Hard to debug this without seeing more code for context. Can you post the composable that’s recomposing and the code that updates that state?
s
I'm not sure it's the correct way to solve this issue, but I have now a map that has Badges and it now only recomposes the item which is change
Copy code
val packBadges = mutableStateMapOf<String,BADGE?>()
and on the Observing side
Copy code
PackItem(
    modifier = Modifier
        .width(boxWidth)
        .padding(horizontal = 8.dp),
    entry.packName,
    entry.lections.map { it.name }.joinToString { it },
    emojiText = entry.emoji,
    coins = entry.coins,
    bagText = packBadges["${entry.lang}${entry.pacId}${entry.packOwnerId}${entry.func}"]
) {
    onPackSelected(entry)
    when(packBadges["${entry.lang}${entry.pacId}${entry.packOwnerId}${entry.func}"]) {
        is OPEN ->  onOpenLections()
        is GET ->  getLections()
        is COIN ->  getLectionsWithCoins(entry.coins)
    }
}