Suppose I have this blazor component (I'm using wasm):
<p>@name</p>
@code{
private int id;
public void SetId(int id) // will be called by another component that has a reference to this component
{
this.id = id;
StateHasChanged();
}
private string name;
private async Task UpdateName()
{
// httpService is injected
this.name = await httpService.Get<string>($"api/getname?id={this.id}");
}
}
How do I manage to call the UpdateName method each time SetId (hence StateHasChanged) is called ?
I tried calling it inside lifecycle methods SetParametersAsync and OnParametersSetAsync. But I think these methods are not being invoked each time StateHasChanged is called. Probably because the component has no parameters.