Blazor seems aware of object changes within components without any external user intervention, for example if I have:
<p>@Data.SomeProperty</p>
<input type="text" @bind="Data.SomeProperty" />
@code {
[Parameter]SomeModel Data {get;set;} // How do I know when this/its internals have changed?
}
Whenever the input changes it seems to understand that it needs to refresh the UI (not sure if its whole UI or just the specific parts changed). So is there a way for a developer to hook into this and be notified when something has changed?
My use case here is I want to be able to have a title
field for a component (ComponentA) but the title is computed within a child component (ComponentB) so I want to be able to have ComponentB raise an event or notify in some way to indicate the computed property has changed then ComponentA can take that change and update its title.
So is there a way to be able to notify externally that the models changed WITHOUT altering the models internals? (Happy for it to be a custom EventCallback
I somehow trigger as long as logic for it lives inside the component not the model)
EventCallback<string>
in ComponentB which represents the "title has changed" event, but how do I KNOW in ComponentB that data has changed? Ultimately I want a way to be able to know inside a component if the params/properties have changed and raise an event off the back of that. Ideally in the scope of a property i.e no point raising "title changed" if some other variable changedData.SomeChildProperty
has changed, which is mainly what I would be wanting to listen for, current Henks answer probably seems to be closest.