Expand description
Dynamic attributes for Yew.
§Example
use yew::{prelude::*, virtual_dom::VTag};
use yew_attrs::{attrs, Attrs};
#[derive(PartialEq, Properties)]
struct ButtonProps {
#[prop_or_default]
pub node_ref: NodeRef,
#[prop_or_default]
pub attrs: Attrs,
#[prop_or_default]
pub children: Html,
}
#[function_component]
fn Button(props: &ButtonProps) -> Html {
props
.attrs
.clone()
.new_vtag(
"button",
props.node_ref.clone(),
Default::default(),
props.children.clone(),
)
.into()
}
#[function_component]
fn App() -> Html {
let on_click = use_callback((), |_, _| {});
html! {
<Button attrs={attrs! {class="text-red" disabled=false onclick={on_click}}}>
{"Click"}
</Button>
}
}
Macros§
- attrs
- Macro to generate dynamic attributes.
Structs§
- Attrs
- Container for dynamic attributes and listeners.
Enums§
- Attrs
Error - Error for Attrs operations.