sonder-joker
08/14/2021, 4:19 AMKirill Grouchnikov
08/14/2021, 5:39 AMCLOVIS
08/14/2021, 8:21 AMCLOVIS
08/14/2021, 10:32 AMArkady Bazhanov
08/14/2021, 11:10 AMuseState
is equivalent to remember { mutableStateOf(...) }
CLOVIS
08/14/2021, 12:52 PMvar a by mutableStateOf(false)
@Composable
fun Foo() {
Text(a)
Button(... { a = !a })
}
and this doesn't:
var a by useState(false)
// “hooks cannot be used outside of functional components”
val Foo = fc {
//...
}
CLOVIS
08/14/2021, 12:54 PMuseState
setter is called, which can only happen locally in a componentCLOVIS
08/14/2021, 12:55 PMremember + mutableStateOf
is much, much more powerful than useState
So if you learned React and you want to learn Compose, yes it is the equivalent, but if you come from Compose and try to learn React (like I did) it doesn't help you at allCLOVIS
08/14/2021, 12:56 PM