Skip to content

Mark fields of property non-optional with attribute #167

@bytesnake

Description

@bytesnake

The following pattern is used to pass states between elements:

#[derive(Props)]
struct ResultsProps {
    current_idx: Option<State<isize>>,
}

#[component]
fn Results(props: &ResultsProps, mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
    let Some(mut current_idx) = props.current_idx else {
        panic!("index is required");
    };

   ...
}

I propose to add an attribute #[iocraft(required)] to mark fields as non-optional when constructing elements

#[derive(Props)]
struct ResultsProps {
    #[iocraft(required)]
    current_idx: State<isize>,
}

#[component]
fn Results(props: &ResultsProps, mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
   ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions