Actually that's not quite what I was trying to do....
# react
c
Actually that's not quite what I was trying to do. I wanted a class component to simply pass all its children on, but adding some props to pass down as well
m
I feel exactly the same way....Here's how I make componenets.
Copy code
interface FooComponentProps : RProps {
    var messageProp: String
}

class FooComponent : RComponent<FooComponentProps, RState>(){
    // all variables inside the Prop and State interfaces are useable inside of the class
    override fun RBuilder.render() {
        div {
            +messageProp
        }
    }
}

fun RBuilder.fooComponent(message: String) = child(FooComponent::class) {
    attrs {
        // The props for FooComponent are set here
        this.messageProp = message
    }
}
You can call FooComponent from
App
like this:
Copy code
class App : RComponent<RProps, RState>() {
    override fun RBuilder.render() {
        fooComponent("some message")
    }
}
🎉 1
c
Thank you for that!
I guess one of the things that's warping my brain is the part where you set the component's props. Shouldn't props be coming from the parent component? And it's weird that we set them in the interface, then use them in the component, then declare them at the end.
d
well, i guess this is how original react lib works
c
I've never used React with something like Typescript and maybe this would be normal and obvious if I had. I've been working with regular javascript react for years now and this seems real strange. Seems weird to need to keep declaring what props are going where
d
i wish we could just pass props instance as fun param to child components or something like that. to have more control on instantiation
👍 1
m
yeah, even in original react your have to explicitly pass props.
c
hm, yeah that’s true. probably just all spun around at the moment that i’m not able to think about this clearly