Question about passing props when using Kotlin/JS ...
# javascript
d
Question about passing props when using Kotlin/JS & React. When you create an element using
Copy code
element = About.create()
How does one go about passing props to the element on creation?
t
Copy code
element = About.create {
    // your props
}
d
Thanks!
Hmm, I must be missing something obvious. The prop is undefined in the child component. This is my parent component. The log statement prints out the webUser's properties.
Copy code
Route {
   path = "/campaigns"
   element = Campaigns.create {
      webUser
   }
   console.log("web user ->>> $webUser")
}
My child is set up like this and webUser is undefined....
Copy code
external interface CampaignWebUserProps: Props {
    var webUser: WebUser
}

val Campaigns = FC<CampaignWebUserProps> {props ->

    val webUser by useState(props.webUser)
...
}
Am I missing something obvious?
t
Copy code
element = Campaigns.create {
    this.webUser = webUser
}
If user data is common - it’s preferrable to use React
Context
instead
d
AHHHH, thanks so much! That works 🙂
Ok, I'll read up on
Context
right now
I also just realize I can handle "injecting" bearer and dealing with refresh automagically with Ktor client so I won't need to do this (above) much longer. But I'm sure I'll want to pass props from parent to child sometime.
t
Components, which I use for routes have no props. With
Context
you avoid redundant rendering for components, which don’t use data directly (for proxies)
🙏 1
👍 1
In next version it will be possible to use
ComponentType
instead