I have the issue that I have an
Input
which on recomposition doesn't update the UI with the latest value, but it
is visible in the DOM tree. The code is a bit like this
@Composable fun EditableTitle(value: String, onInputChange: (String) -> Unit = {}) {
var editMode by remember { mutableStateOf(false) }
val nativeElement = remember { mutableStateOf<HTMLInputElement?>(null) }
// I need to use this as a hack to overwrite the value so that it works
LaunchedEffect(value) {
nativeElement.value?.value = value
}
LaunchedEffect(editMode, nativeElement.value) {
when {
editMode -> nativeElement.value?.select()
!editMode && nativeElement.value != null -> {
nativeElement.value?.value?.also(onInputChange)
nativeElement.value?.blur()
}
}
}
Input(InputType.Text) {
placeholder("Enter list name...")
defaultValue(value) // when I use value(value) it blocks my UI
refState(nativeElement) // this one uses DisposableEffect to fetch the nativeElement
if (editMode && evt.key == "Enter") {
editMode = false
}
}
}
I do some stuff with some other state variables to make it more UI friendly. The
value
parameter can be updated externally as well and when it has been modified at least once in the above Composable, the UI doesn't update if the input value into the composable is changed. When I use the
LaunchedEffect(value)
it works. Is this logical?