https://kotlinlang.org logo
#compose
Title
# compose
c

CLOVIS

08/06/2021, 10:26 AM
React doesn't allow to use hooks conditionally (differently each render):
val Component = fc<RProps> {
if (…)
useRef() // big no no
}
Is that an issue Compose shares? Or is this safe?
@Composable
fun Component() {
if (…)
val a by remember { … }
}
(ignoring that Kotlin doesn't allow a
val
declaration in a braceless-
if
)
a

Andrey Kulikov

08/06/2021, 11:15 AM
yes, it is fine
c

CLOVIS

08/06/2021, 12:02 PM
Really? That's one of the big pain points of React for me, really good to know
o

Oleg Khotskin

08/06/2021, 12:38 PM
Thanks to the compiler plugin I suppose.
a

Andrey Kulikov

08/06/2021, 1:07 PM
this remembered object lives while the condition is true, that is completely fine