Jonathan Lennox
07/15/2024, 5:20 PMJonathan Lennox
07/15/2024, 5:20 PMimport org.w3c.dom.HTMLInputElement
import org.w3c.files.File
import react.RBuilder
import react.RComponent
import react.PropsWithChildren
import react.State
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.input
import react.setState
import web.html.InputType
class Dump : RComponent<PropsWithChildren, DumpState>() {
init {
state.file = null
}
override fun RBuilder.render() {
console.log("blah")
if (state.file == null) {
div {
input {
attrs {
type = InputType.file
onChange = { event ->
val file = (event.target as HTMLInputElement).files?.item(0)
console.log("got file ", file)
setState {
this.file = file
}
}
}
}
}
} else {
child(DumpViewer::class) {
attrs {
file = state.file!!
}
}
}
}
}
external interface DumpState : State {
var file: File?
}
Jonathan Lennox
07/15/2024, 5:21 PMfunction Dump$render$lambda$lambda$lambda(this$0) {
return function ($this$attrs) {
// Inline function 'web.html.InputType.Companion.file' call
InputType;
$this$attrs.type = 'file';
$this$attrs.onChange = Dump$render$lambda$lambda$lambda$lambda(this$0);
return Unit_instance;
};
}
which fails at runtime with
InputType is not defined
ReferenceError: InputType is not defined
Jonathan Lennox
07/15/2024, 5:22 PMtype = js("\"file\"")
but that shouldn't be necessary. Am I don't something wrong, or is this a bug somewhere?Jonathan Lennox
07/15/2024, 6:31 PMturansky
07/15/2024, 8:14 PMFC
from kotlin-react
:
1. You won’t need redundant attrs
2. You will have strict events (with strict currentTarget
)Jonathan Lennox
07/15/2024, 8:17 PMturansky
07/16/2024, 8:11 AMturansky
07/16/2024, 8:13 AMuseState
Class methods -> useCallback