I have a Markdown file in my project at `composeRe...
# compose
d
I have a Markdown file in my project at
composeResources/files
. How would I got about extracting the text in that file from a Composable?
1
Ah, I think I found what I want:
Copy code
var bytes by remember {
    mutableStateOf(ByteArray(0))
}
LaunchedEffect(Unit) {
    bytes = Res.readBytes("files/somefile.md")
}
Text(bytes.decodeToString())
Edit: This works!
k
I'd say it is better to decode to a string inside the launched effect
d
Great call, I had the same thought a moment ago. I am making that optimization in my next work session.
y
Doesn't LaunchedEffect default to main dispatcher?
So maybe pull out to a suspending function that also uses Dispatchers.IO?
1
d
@yschimke this code is running in the web using WASM. I'm no web developer but I did not think IO threads are even a thing there. Are they?
k
Almost all resources are read synchronously in the caller thread. The only exceptions are raw files and all of the resources on the JS platform that are read asynchronously.
y
Ahhh, ok. missed that. I assumed compose on android
d
@Konstantin Tskhovrebov So does that mean I can use
<http://Dispatchers.IO|Dispatchers.IO>
?
k
yes
d
Sweet!
Thanks