Yes, in general, things in compose require some kind of initial value, it can’t simply be “absent”. You must acknowledge that the “value” should be before you actually set it, because Compose is potentially going to be trying to read that value before you even get a chance to set it in your code. The only way for Compose to be able
know it will have a value available is if an initial value is required at the point that you call
mutableStateOf()
.
And to this specific snippet, I wouldn’t call the
Initial
state a “throwaway value”, since it communicates valuable information, both to you, the programmer, and to the end-user. Especially if it takes time to connect to the Bluetooth device, your app might be left in that
Initial
state for a while, and you should display an appropriate message to the user during that time like “Attempting to connect”