The child component constructs a field based on a set of properties of an object that is passed to child as a parameter. In the below example, how can the child component render dynamically when any of the address fields change in the parent ? Thanks for any suggestions!
The parent component uses a child component as below and passes a parameter parentObj
.
Parent Component:
<Child ChildObj="@parentObj" />
Child component:
<div class="col-8 flex-wrap">
@Address
</div>
@code {
[Parameter]
public Person ChildObj { get; set; }
public string Address { get; set; }
protected override async Task OnInitializedAsync()
{
await Task.Run(() => {
if (ChildObj != null)
{
Address = ChildObj.Address1 + " " + ChildObj.Address2 + " " + ChildObj.City + " " + ChildObj.State + " " + ChildObj.Zip
}
});
}
}
InvokeAsync(StateHasChanged)
- Peter Morris