-
Hi, In React, you can make the following component: function MyComponent({ header, children, footer }: { header?: ReactNode, children: ReactNode, footer?: ReactNode }) {
return (
<div>
<div>{header}<div>
<p>{children}</p>
<div>{footer}</div>
</div>
)
} Then use it as follows:
My question is: how can I do the same in Leptos? I know how to pass in the child, but I cannot figure out how to pass props that are views through props other than children. Is it possible? For context; I am a noob. Thanks for letting me know! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We tend to do this through what are sometimes called "render props" in React: a prop that is a function that returns some kind of view. An example of this would be the If you want to do something similarly in your own component, the easiest way to do this is to take a prop whose type is |
Beta Was this translation helpful? Give feedback.
We tend to do this through what are sometimes called "render props" in React: a prop that is a function that returns some kind of view.
An example of this would be the
Show
component in the core library, which takes a fallback likefallback=|| view! { <Small/> }
.If you want to do something similarly in your own component, the easiest way to do this is to take a prop whose type is
ViewFn
. Here's howShow
does it.