Skip to content

How to pass in a view to a prop other than children #3167

Answered by gbj
nmattela asked this question in Q&A
Discussion options

You must be logged in to vote

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 like fallback=|| 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 how Show does it.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nmattela
Comment options

Answer selected by nmattela
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants