yewstack/yewtil

Function Components

hgzimmerman opened this issue · 1 comments

Allow deriving components for functions.

With https://blog.rust-lang.org/2019/11/07/Rust-1.39.0.html#attributes-on-function-parameters, it should be possible to ferry attributes like #[props(required)] from function parameters to a derived props struct.

This could look like:

#[derive(FunctionComponent)]
#[fn_comp_name(ShowThing)]
#[fn_comp_memo] // actively memoize the inputs.
fn show_thing<T: Component>(
    #[props(required)]
    callback: Callback<()>
) -> Html<T> {
    ...
}

The type parameter on Html will likely soon not be needed, making this much more easily to accomplish.

#[derive(FunctionComponent)]
#[fn_comp_name(ShowThing)]
#[fn_comp_memo] // actively memoize the inputs.
fn show_thing(
    #[props(required)]
    callback: Callback<()>
) -> Html {
    ...
}