Hi all 👋,
I have a query regarding
mutableState
.
From the docs (
https://developer.android.com/develop/ui/compose/state#state-in-composables),
I see that I can create a
mutableState
using either of these syntax.
var id: Int? by remember {
mutableStateOf(null)
}
val setId = { updatedId: Int? ->
id = updatedId
}
OR
val (id: Int?, setId) = remember {
mutableStateOf(null)
}
I want to pass the method
setId
to function that has the method signature as
setId: (Int?) -> Unit
.
The first syntax where the
setId
was manually created by me has the required method signature as expected, but the setter method in the second syntax has the method signature as
(Nothing?) → Unit
.
So, I am getting a data type mismatch error.
Can anyone please share why this happens, and what is the best way to do this?
thank you color