How can I pass a fc to other fc's props? My use ca...
# react
n
How can I pass a fc to other fc's props? My use case is that I want to pass another component alongside the children I am already passing into my functional component
Copy code
val chatSidebar = fc<ChatProps> { props -> // the fc that I want to pass 
-----
external interface SidebarProps : PropsWithChildren {
    var sidebarContent: FunctionComponent<Props> // want to pass it here
}

val sidebar = fc<SidebarProps> { props ->
   div { props.sidebarContent } // somehow do something like this
   props.children() //already using children for the main content
This is how I want to use the sidebar
Copy code
sidebar {
        when (child) {
            is Main.Child.Chat -> {
                attrs.sidebarContent = chatSidebar{} // add the corresponding content to the props alongside the main content
                chat { attrs.component = child.component} // the child/ main content
t
If
sidebarContent
is
FC
:
Copy code
div { props.sidebarContent() }
n
@turansky hey sorry victor, got two questions, with this approach, how can I pass props to this content now?
No value passed for parameter 'handler'
Copy code
div { props.sidebarContent() }
When they come from the parent component And another one is how to actually assign the functional component to the attribute.
Copy code
This is the sidebarcontent
external interface ChatSidebarProps : Props {
    var component: Chat
}

val chatSidebar = fc<ChatProps> { props ->
t
sidebar: ReactNode
Copy code
attrs.sidebar = createElement(ChatSidebar, jso { component = ... })
also you can use
buildElement
to build isolated node
createElement
is fine, if you have just one element
n
Can I ask about this part
jso { component = ... })
Jso is not resolved, maybe I am a bit outdated on the dependencies Edit: probably jsobject?
t
jso
- short alias for
jsObject
n
Thanks @turansky, never would've gotten this to work myself
t
Most magic described here