yew icon indicating copy to clipboard operation
yew copied to clipboard

Allow assigning &str and String to `Option<Html>`

Open ctron opened this issue 2 years ago • 2 comments

While it is possible to assign &str and String to a property of type Html, that fails for Option<Html>. I think this should be possible too.

Yew: 0.21

ctron avatar Oct 05 '23 17:10 ctron

Could you provide more context on what are you trying to assign them to?

its-the-shrimp avatar Oct 05 '23 19:10 its-the-shrimp

Sure, something like this:

#[derive(PartialEq, Properties]
struct FooProperties {
  pub title: Option<Html>,
}

#[function_component(Foo)]
fn foo(props: &FooProperties) -> Html {
  html!(
    if let Some(title) = &props.title {
      <h1>{ title.clone () }</h1>
    }
  )
}

#[function_component(Example)]
fn example() -> Html {
   html!(<Foo title="Title"/>)
}

The reason to use `

ctron avatar Oct 06 '23 06:10 ctron