Slide 20
Slide 20 text
State Hoisting
Moving state out of the composable.
Stateless
Stateful
Doesn’t have a state, not hold, define, or
modify any state.
Owns a piece of state that can change
overtime.
EditableTextView(
text = R.string.total_amount,
value = amount,
onValueChange = { amount = it },
KeyboardOptions(keyboardType =
KeyboardType.Number).copy(
imeAction = ImeAction.Next
),
R.drawable.ic_money
)
var amount by remember {
mutableStateOf("") }
var tip by remember { mutableStateOf("")
}
var tipSwitchChecked by remember {
mutableStateOf(false) }
val resultAmount =
amount.toDoubleOrNull() ?: 0.0
val resultTip = tip.toDoubleOrNull() ?:
0.0
val resultantTip = tipCalculator(
resultAmount,
resultTip,