What's the difference between functionalComponent(...
# react
b
What's the difference between functionalComponent() and rFunction()?
a
I think on returns an
RClass
while another returns a
ReactElement
. But they work and behave the same
b
Why would anyone use
functionalComponent()
over
rFunction()
??
Copy code
// given
val A = functionalComponent<RProps>() {}
val B = rFunction<RProps>("B") {}

// usage
fun RBuilder.render() {
  child(A) {
    attrs {
      ...
    }
  }
  B {
    attrs {
      ...
    }
  }
}
B seems to be much easier to use and read...
a
Interop reasons. Some methods would require you to pass or return an
ReactElement
(i.e.
buildElement
) and some methods need to you to pass or return
RClass
i.e. (
RBuilder.child(el: RClass)
). Use one or the other whenever you need em
👍 2
a
They are same. Just legacy that should be solved. I’ve added
functionalComponent
with adding hooks to wrappers because didn’t noticed that there’s
rFunction
that is functional component.
Now i think that best naming is
rComponent
to be similar with
RComponent
class. But there already are
rFunction
and
functionalComponent
, it think that i should deprecate
rFunction
and then remove it as less obvious and discoverable naming.
b
I personaly prefer rFunction over functionalComponent because its usage is less verbose
a
what about
rComponent
?
b
A bit too ambiguous, don;t you think? Since Component can be either functional or class-based
But don't mind it all that hard
t
+1 for
rComponent