What's the difference between these 2? ```#1 fun R...
# react
b
What's the difference between these 2?
Copy code
#1
fun RBuilder.Component(prop1:String, prop2:String) {}

#2
interface ComponentProps: RProps {
  var prop1: String
  var prop2: String
}
val Component = rFunction<ComponentProps>("Component"){}
m
The former is not a component but merely adds children to another component when called. The latter is a component and can have state. And because it's functional it can also use hooks.
b
So if I were to add hooks in both and use them in for loop the former would break?
m
Yes, if the loop size changes or the component that uses your function changes its own structure. Your function is basically adding hooks to another component.
b
And by sayng "is able to have state" you mean via hooks? Not conventional state like class Components?
m
Yes. State for fn components is based on hooks
b
Got it, thanks
Looks like
rFunction
is unusable with IR. When doing
Copy code
interface ComponentProps: RProps {
  var prop1: String
  var prop2: String
}
val Component = rFunction<ComponentProps>("Component"){}

fun RBuilder.test() = Component {
  attrs {
    prop1 = "a"
    prop2 = "b"
  }
}
I'm getting
this_0_.setProp1() is not a function
m
Props must be an
external interface
b
Oh... Works with Legacy, though
m
Yeah but it probably shouldn’t :)