SHORT ANSWER:
You use remember in Android Compose when you want to remember the value.
LONG ANSWER:
The mechanism works as follows when a state variable changes then recomposition is triggered, and you see the updated screen on your mobile.
For example:
Case 1
@Compose
fun MyComposable(){
var text: String = ""
TextField(
value = text,
onValueChange = { newText ->
text = newText
}
}
In this case: when you press a button on your keyboard nothing is happening because you do not have a state value that compose mechanism looks in order to update your screen. In this case when you press a letter on your keyboard nothing happens at all.
Case 2
@Compose
fun MyComposable(){
var text by mutableStateOf("")
TextField(
value = text,
onValueChange = { newText ->
text = newText
}
}
In this case you have a state variable (in our case a string), and when you press a button on your keyboard recomposition is happening. So the mechanism says hey look the value has changed, let me recompose the screen with this composable then the block runs again, and text variable defaults to an empty string("") again. So even though recomposition happened you see the same thing on your screen.
Case 3
@Compose
fun MyComposable(){
var text by remember { mutableStateOf("") }
TextField(
value = text,
onValueChange = { newText ->
text = newText
}
}
In this case lets say you want to type the number 10 on your keyboard. You click 1 mechanism sees the state value has changed. Then mechanism executes composable function again when at text value it does not default it to "" but keeps or remembers the 1 you pressed before. So you see 1 on your screen and you can press 0 and see 10 finally...
So when is useful to use remember? Since the block of a composable may run several times and in unexpected ways, you should use a remember{} when you want your variable to survive this re-execution of code. In other words if you have a constant value you do not care and you do not want to remember it. On the other side if you want an animation to happen you want the value to be remembered between two points so remember should be use. For complex calculations of course it is better to transfer this code to a ViewModel as stated from @nglauber.