It's because the composable function is now "stateless", meaning it will not change anything in its scope.
It's simple because:
For every input, the function has the same output (since it only relies on its inputs and does not change anything on the outside).
It becomes very testable (because of 1).
It gives the power to anyone that is using it. They can "change" the state however they want. Imagine a TextField(text: String, onTextChanged: (text: String) -> Unit)
. You can change the state however you want (for example, remove any digits from the string and then apply it to your state). If TextField
handled the state itself, It would always change the state to the actual text (and you would need another mechanism for the said scenario).
This brings a simplicity to your composable as you do not have to worry about how your composable (e.g. TextField
) changes a state.