Skip to content

Preferred way to build custom components with builder syntax #2640

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

You must be logged in to vote

I guess I'm not sure whether you are mostly talking about using your own components, or using the built-in control flow components (Show, Suspense, etc.)

For your own components, you can of course just write a function instead of using the component macro. The macro is mostly useful so we can have named arguments in the XML-like syntax.

For example here's a perfectly reasonable way to have a component with children with no macros:

#[component]
pub fn App() -> impl IntoView {
    WithChildren(|| p().child("foo bar").into_view())
}

pub fn WithChildren(children: impl FnOnce() -> View) -> impl IntoView {
    div().child(children())
}

If you're talking about the built-in components that take …

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@spencewenski
Comment options

@gbj
Comment options

@spencewenski
Comment options

@gbj
Comment options

@spencewenski
Comment options

Answer selected by spencewenski
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