andylamax
06/30/2020, 10:13 PMexternal interface DumbProps {
var name: String
}
val DumbComp = functionalComponent<DumbProps> {
div { +"Hi, I am ${it.name}" }
}
Then, I would have to create an extension for RBuilder like so
fun RBuilder.DumbComp(props: DumbProps,handler:RHandler<DumbProps>) = child(DumbComp,props,handler)
This makes the usage of functional components and hooks so verbose.
Advice: RBuilder should add a member function to ease use of functional components and hooks like so
class RBuilder{
. . .
operator fun <P : RProps> FunctionalComponent<P>.invoke(
props: P = jsObject(),
handler: RBuilder.(P) -> Unit
) = child(this, props, handler)
. . .
}
So that now, I can just go and call
DumbComp {
attrs.name = "Andy"
}
frank
07/02/2020, 11:45 PMRProps
?
Like This:
val DumbComp = functionalComponent<RProps> { props ->
div { +"Hi, I am $props["name"]" }
}
andylamax
07/03/2020, 7:18 AMfun <P : RProps> RBuilder.Component(props: P = jsObject(), builder: RBuilder.() -> Unit) = child({
buildElements {
builder()
}
}.unsafeCast<FunctionalComponent<P>>(), props)
If I have a simple Component like the one you said, I just do,
fun RBuilder.DumbComp(name:String) = Component<RProps>{
div { +"Hi, I am ${name}}"}
}
So now you can just call your component
DumbComp("Andy") or DumbComp(name = "Andy")