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

Blazor two-way binding across more than two components (clarification on this documentation) #57962

Open
adamgf1 opened this issue Sep 19, 2024 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components Docs This issue tracks updating documentation
Milestone

Comments

@adamgf1
Copy link

adamgf1 commented Sep 19, 2024

Hi,

I see the contributing guidelines encourage general feedback and discussions here, so hopefully this is the place for this question.

This is regarding the Bind across more than two components example in the documentation.

I've been reading these pages a lot in the past few days, trying to get my head around the details, and there's one thing I'm not clear on:

In the example linked above, where the NestedChild.razor component is essentially acting as a pass-through between the Parent2.razor and NestedGrandchild.razor components, is there a meaningful difference between what the example shows by using @bind:get/@bind:set modifiers:

    <NestedGrandchild @bind-GrandchildMessage:get="ChildMessage" 
        @bind-GrandchildMessage:set="ChildMessageChanged" />

And something like this, where I'm passing down the parameter and event callback as "normal":

    <NestedGrandchild GrandchildMessage="ChildMessage" 
        GrandchildMessageChanged="ChildMessageChanged" />

?

My understanding so far is leading me to believe that the exact way that the example is written, to use the @bind:get and @bind:set modifiers, is not actually necessary in this case, and it's not necessary because of the way the NestedChild.razor component happens to have its parameter/callback matching the type (string) of the NestedGrandchild.razor component's parameter/callback, and isn't:

  • Giving the NestedGrandchild.razor component anything different to its own ChildMessage parameter value on the way down
  • Changing the string given by NestedGrandchild.razor's GrandchildMessageChanged event callback on the way up

In other words, I think I can see why the bind syntax should be used for example if the NestedChild.razor component wanted to transform the string given by the NestedGrandchild.GrandchildMessageChanged event callback, before in turn passing it up to the Parent2.razor component via the NestedChild.ChildMessageChanged event callback.

But in the way that the example is actually written, where no such transformations are going on, I guess my main question is whether there's a reason why the @bind syntax should be used in this kind of scenario, as opposed to using the other example snippet I gave where the straight passing-through of the parameter and callback is done from child to grandchild component?

(The reason I ask is that I have this exact situation in the code I'm working on, and the current implementation is using the passing through of parameters and callbacks approach, without @bind, and so I'm trying to figure out if I'm missing something important by not having this code follow the way the documentation example is written.)

Hopefully that's a clear enough explanation, thanks in advance for any clarification on this.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Sep 19, 2024
@guardrex
Copy link
Contributor

Apologies, @adamgf1. I was just looking at our doc disscussions when I posted that.

I'll keep an 👁️ on this ... one of the Blazor engineers will respond to you shortly here. If we need a docs issue to modify that section, I'll open it after the discussion concludes here.

@adamgf1
Copy link
Author

adamgf1 commented Sep 19, 2024

Hi @guardrex, not sure what post you're referring to but whatever the case no apology is necessary 😃

Now that you mention doc discussions, I realise this really should have gone into AspNetCore.Docs, shouldn't it. Sorry about that.

@guardrex
Copy link
Contributor

I was referring to a comment that I deleted and then replaced ☝️ there.

No problem opening this here, as I'd need to ask them to look at your issue anyway. The content that you're referring to was approved multiple times over the years when it was first provided several years ago and updated a few times since then, but we might end up with new content based on the discussion here. I'm 👂 to see where your question goes.

@MackinnonBuck MackinnonBuck added the Docs This issue tracks updating documentation label Sep 19, 2024
@MackinnonBuck MackinnonBuck added this to the 9.0.0 milestone Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Docs This issue tracks updating documentation
Projects
None yet
Development

No branches or pull requests

4 participants
@guardrex @MackinnonBuck @adamgf1 and others