I'm trying to create components made up of smaller components related to data bound from the parent, but I'm not capable of updating the variables in those child components. The idea of doing it this way is to be able to reuse them in other components.
I will show a small example.
When the father component is called OnInitializedAsync add values to the list, that are shown in child 2 component correctly, but if I add a new element to that list in the other child 1 component the list is never updated in view (the data has been update in database)
Father component (base list variable)
<CascadingValue Value="@thelist">
<Child1></child1>
<Child2></child2>
<CascadingValue>
@code {
private List<thetype> thelist { get; set; }
protected override async Task OnInitializedAsync()
{
thelist = service.loadvalues()
}
}
Child component 1 (add values to list)
Button UpdateList
@code {
[CascadingParameter]
public List<thetype> thelist { get; set; }
private async Task UpdateList()
{
thislist changed
}
}
Child component 2 (show list)
Show list
@code {
[CascadingParameter]
public List<thetype> thelist { get; set; }
}
I have tried also using EventCallback, that is the way I use to pass parameters, but this way also is not working is a parameter is shared with multiple cascading components.
<Child1 thelist="@thelist"></child1>
<Child2 thelist="@thelist"></child2>
[Parameter]
public List<thetype> thelist{ get; set; }
[Parameter]
public EventCallback<ChangeEventArgs> thelistChanged { get; set; }
And using StateHasChanged, but the result is the same.
In both ways the updated list can be shown in father component with the new values, but not in the child list component.
I hope you understand what I am trying to ask. All the posts and articles I find are about passing parameters between components, but that's not really my question. I intend that when a component informs the parent of a change, that change is replicated to all descendant components of that parent.
Thanks.