Error:_Reading a state that was created after the ...
# compose-desktop
s
Error:_Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied._ Occurs when I lauch a coroutine in Dispatcher.IO to change value of mutableState. Some has suggest to use LaunchedEffect,but for me it doesnt seem to be working i.e the job doesnt execute(bcuz launched effect seems to dont run unless we change key). is there any other Workaround?
a
Can you post the code where you launched this coroutine?
The answer is indeed likely to be to use
LaunchedEffect
but seeing the surrounding environment would help to form more specific advice
s
@Adam Powell
I tried something like this , but Image doesnt seems to be recomposing , here ImageLoad is a composable consuming pic. Any other workaround?
a
ah, yes. The effect key here is the URL you're loading from. If that URL changes, you want to cancel a previous load in progress and start a new one. It's also important to
remember
that
MutableState
object. e.g.
Copy code
var pic by remember { mutableStateOf<ImageBitmap?>(null) }
LaunchedEffect(coverUrl) {
  pic = loadImage(coverUrl)
}
s
i tried using the url as key , but didnt seem to work, but i forgot to remember , will try later , and hope it may work. Thanks👍
👍 1
101 Views