Macro yew::props[][src]

props!() { /* proc-macro */ }
Expand description

Build Properties outside of the html! macro.

It’s already possible to create properties like normal Rust structs but if there are lots of optional props the end result is often needlessly verbose. This macro allows you to build properties the same way the html! macro does.

The macro doesn’t support special props like ref and key, they need to be set in the html! macro.

You can read more about Properties in the Yew Docs.


use std::borrow::Cow;

#[derive(Clone, Properties, PartialEq)]
struct Props {
    id: usize,
    name: Cow<'static, str>,

struct Model(Props);
impl Component for Model {
    type Properties = Props;
    // ...

// You can build props directly ...
let props = yew::props!(Props { name: Cow::from("Minka") });
// ... or build the associated properties of a component
let props = yew::props!(Model::Properties { id: 2, name: Cow::from("Lemmy") });

// Use the Rust-like struct update syntax to create a component with the props.
html! {
    <Model key=1 ..props />