https://kotlinlang.org logo
Title
n

Norbi

11/12/2021, 1:19 PM
What is the preferred
Input
usage style: controlled or uncontrolled? How can I decide?
a

Akif Abasov [JB]

11/12/2021, 1:36 PM
I think that controlled is useful in most simple cases and uncontrolled for complicated scenarios.
👍🏻 1
So use controlled while you can
👍🏻 1
:tnx: 1
o

Oliver.O

12/01/2021, 3:09 PM
With controlled TextInput fixed in beta4 (#1169), what are the remaining use cases for uncontrolled inputs? I am working on an MDC text field for Compose, which needs to synchronize the state of a floating label and an outline notch with its input. This seems way easier when not exposing the uncontrolled API. I wonder whether there is any downside when only the controlled API is available for component users.
a

Akif Abasov [JB]

12/01/2021, 3:50 PM
Reasons to have both are same as in react : https://reactjs.org/docs/uncontrolled-components.html
Since an uncontrolled component keeps the source of truth in the DOM, it is sometimes easier to integrate React and non-React code when using uncontrolled components. It can also be slightly less code if you want to be quick and dirty. Otherwise, you should usually use controlled components.
:thank-you: 1
1
o

Oleksandr Karpovich [JB]

12/01/2021, 4:00 PM
If you're implementing a new component you can make "controlled" only for the beginning until you see a need to have it uncontrolled.
:thank-you: 1
o

Oliver.O

12/01/2021, 5:04 PM
So at least in my MDC use case, it's just the opposite: Easier to integrate in controlled mode. I'll be following that path until YAGNI evaluates to
false
.