-
Is there a way to pass attributes like "class" or "id" to the root node ? If I do this #[component]
fn MyComponent(cx: Scope) -> impl IntoView {
view! { cx
<div>Foo</div>
}
}
#[component]
fn App(cx: Scope) -> impl IntoView {
view! { cx,
<MyComponent class="foobar" />
}
} I have an error saying that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The short answer: No, you can't pass HTML element attributes directly to components are component props. They're conceptually different things: think of the component props as function arguments. The compiler is helpfully telling you that there's no #[component]
fn MyComponent<'a>(cx: Scope, class: &'a str) -> impl IntoView {
view! { cx
<div class=class>Foo</div>
}
} or use a String or whatever type you'd like, if you don't want to deal with the lifetime annotation |
Beta Was this translation helpful? Give feedback.
The short answer: No, you can't pass HTML element attributes directly to components are component props. They're conceptually different things: think of the component props as function arguments. The compiler is helpfully telling you that there's no
class
prop onMyComponent
, which is true. You can add one and pass it through to the HTML element.or use a String or whatever type you'd like, if you don't want to deal with the lifetime annotation