Skip to content

props of type Option<T> cannot use None #3747

Open
@arcollector

Description

@arcollector

Problem

Hello there, I have this simple code

#[derive(Properties, PartialEq)]
pub struct Props {
    pub id_patient: Option<String>,
    pub id_report: Option<String>,
}

#[function_component(PatientsNavBar)]
pub fn patients_nav_bar(
    Props {
        id_patient,
        id_report,
    }: &Props,
) -> Html {
 html! { /* */ }
}

#[function_component(App)]
fn app() -> Html {
  html! {
     <PatientsNavBar id_patient={None} id_report={None} />
  }
}

the compiler outputs the following the error

type annotations needed
multiple `impl`s satisfying `std::option::Option<_>: IntoPropValue<std::option::Option<std::string::String>>` found in the `yew` crate:
- impl IntoPropValue<std::option::Option<std::string::String>> for std::option::Option<&'static str>;
- impl<T> IntoPropValue<T> for T

Could anybody bring me some light on this matter, how to set an optional prop ?

Environment:

  • Yew version: [ master]
  • Rust version: [1.81.1]
  • Target [wasm32-unknown-unknown]
  • Build tool [trunk]

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions