I've noticed that `TextField` param `placeholder` ...
# compose
r
I've noticed that
TextField
param
placeholder
gets called many times when the
placeholder
in question gets rendered, it gets re-called many many times (18-24, not sure the criteria). is this simply something that just is, or is this a bug/avoidable? i have not been able to find much information on it
j
Composable functions might be re-executed as often as every frame, such as when an animation is being rendered.
https://developer.android.com/jetpack/compose/mental-model#recomposition
r
composition/recomposition is the hardest thing for me to wrap my head around for some reason. not 100% sure how to make my ui not recompose when calling a function.
i have found the issue, i was putting something in
placeholder
that was not `remember`ed and it would keep calling because it didn't know whether or not to consider that thing to trigger a recomposition (i think?)
Copy code
placeholder = {
    val placeholderText = getSomeString()
    Text(placeholderText)
}
to
Copy code
placeholder = {
    val placeholderText by remember { mutableStateOf(getSomeString()) }
    Text(placeholderText)
}
fixed the issue completely
👌 1
k
Out of curiosity, how did you find out how often it recomposed?
z
Couple things: 1. It looks to me like placeholder lambdas should be skippable, just from the source code (would need to check compiler reports to be sure). But if they are, then the only reason for them to recompose would be if some snapshot state was read that changed, which it doesn't look like is happening in your code. So I'm not sure why your placeholder would be recomposing based on the code you provided. 2. You don't need to use
mutableStateOf
if you never change the value. In your code
remember
{
getSomeString()
}
would be sufficient.