Hi, how can I add or remove components of my user ...
# compose
m
Hi, how can I add or remove components of my user interface at run time? tanks
y
Use a
if
block, ie:
Copy code
val shouldShow = +state { true }

if (shouldShow) {
    Button(...)
}

// To show or hide button:
state.value = true
state.value = false
👍 1
You can also use a
@Model
annotated class instead of a state
Copy code
@Model
class MyModel(
   var shouldShowButton: Boolean = false
)

val model = +model { MyModel() }

if (model.shouldShowButton) {
   Button(...)
}

model.shouldShowButton = false