Skip to content

Data binding example shows component overwriting its own parameter value #19789

@SteveSandersonMS

Description

@SteveSandersonMS

We tell people not to create components that overwrite their own parameters, but unfortunately one of the examples in the docs does exactly that: https://docs.microsoft.com/en-us/aspnet/core/blazor/components/data-binding?view=aspnetcore-3.1#child-to-parent-binding-with-chained-bind

This has led to some confusion, e.g., dotnet/aspnetcore#25377

Could we please update the docs not to do that? In the case of the password example, I think the child component could simply omit the line that does Password = e.Value.ToString(); and it should still work fine.

Also the info at https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-3.1#overwritten-parameters-with-renderfragmentis a little misleading. It says that:

Parameters are overwritten under the following conditions:

  • A child component's content is rendered with a RenderFragment.
  • StateHasChanged is called in the parent component.

I would instead say something like New parameter values are supplied, typically overwriting existing ones, when the parent component re-renders. There's no reason to talk about renderfragments or StateHasChanged here, as far as I know. The parent component doesn't even necessarily have a StateHasChanged method, as that's specific to ComponentBase which not all components necessarily derive from.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions