In a grocery list app, I have a parent component looping over grocery items, and a child component showing details for each grocery item using input elements (a checkbox and a text field). I've set up two-way binding directly to the GroceryItem members and it's working fine as far as updating the members with input data.
Where I have a problem is to notify the parent component to re-render itself. I know I have to invoke an EventCallBack when I detect a change, but I want to avoid duplicating my class members as local variables, just to be able to use the setter for detecting the change and invoke the EventCallBack. The other trick I found was to manually bind the data, but again this create duplication since I have to set up an event handler for each input element.
Is there a better way?
I wish there was a mechanism by which I could add more onchange event handlers to the input elements, in order to invoke EventCallBack... But because bind takes up the only slot available I can't.
// This is the child component
<li>
<input type="checkbox" @bind=Item.Purchased />
<input type="text" @bind=Item.Name />
</li>
@code
{
[Parameter]
public GroceryItem Item { get; set; }
[Parameter]
public EventCallback<GroceryItem> ItemChanged { get; set; }
}