field
fun <Field : PreviewLabField<*>> field(key: String? = null, builder: PreviewLabScope.FieldBuilderScope.() -> Field): Field
Creates a field and returns the PreviewLabField instance itself. Unlike fieldState, which returns a MutableState for use with Kotlin's property delegation, this function returns the field instance directly, giving access to field properties and methods.
Use fieldState if you only need the value with property delegation syntax (var x by fieldState { ... }). Use fieldValue if you do not need to update the value.
PreviewLab {
val myTextField = field { StringField("myText", "initialValue") }
TextField(
value = myTextField.value,
onValueChange = { myTextField.value = it },
)
}Content copied to clipboard