AttributeInterceptor

Function AttributeInterceptor 

Source
pub fn AttributeInterceptor<Chil, T>(
    props: AttributeInterceptorProps<Chil, T>,
) -> impl IntoView
where Chil: Fn(AnyAttribute) -> T + Send + Sync + 'static, T: IntoView + 'static,
Expand description

Intercepts attributes passed to your component, allowing passing them to any element.

By default, Leptos passes any attributes passed to your component (e.g. <MyComponent attr:class="some-class"/>) to the top-level element in the view returned by your component. AttributeInterceptor allows you to intercept this behavior and pass it onto any element in your component instead.

Must be the top level element in your component’s view.

§Example

Any attributes passed to MyComponent will be passed to the #inner element.

use leptos::attribute_interceptor::AttributeInterceptor;

#[component]
pub fn MyComponent() -> impl IntoView {
    view! {
        <AttributeInterceptor let:attrs>
            <div id="wrapper">
                <div id="inner" {..attrs} />
            </div>
        </AttributeInterceptor>
    }
}

§Required Props

  • children: [Chil]
    • The elements that will be rendered, with the attributes this component received as a parameter.