Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: spread component attrs #2534

Merged
merged 4 commits into from
Apr 17, 2024
Merged

feat: spread component attrs #2534

merged 4 commits into from
Apr 17, 2024

Conversation

Upbolt
Copy link
Contributor

@Upbolt Upbolt commented Apr 16, 2024

Solves #2403

In the following code Bar will not inherit attributes from Foo when it spreads its attributes

fn main() {
    let (count, set_count) = create_signal(0);

    mount_to_body(move || {
        view! {
            <Foo
                attr:hello=move || count.get().to_string()
            />

            <button on:click=move|_| { set_count.update(|count| *count += 1) }>"+ count"</button>
        }
    });
}

#[component]
fn Foo(#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>) -> impl IntoView {
    view! {
        <Bar {..attrs} />
    }
}

#[component]
fn Bar(#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>) -> impl IntoView {
    view! {
        <div {..attrs}>"hello world"</div>
    }
}

This PR allows for this functionality

@bram209
Copy link
Contributor

bram209 commented Apr 16, 2024

This is great, personally I found it confusing that HTML components behaved differently from custom components and think this is a great addition DX wise 👍

@benwis
Copy link
Contributor

benwis commented Apr 17, 2024

Thanks for the PR, can't say I've tried to do this before. Definitely going to try it though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants