0
votes

Similar to React Blazor re-renders child components when its parameters ("props" in React) change.

That works as expected with primitive types, but I haven't figured out yet how to control that for custom types.

It seems that simple objects are always considered different, even if the object doesn't change:

@page "/"

<h1>Hello, world!</h1>

<Nested Object="@myObject" />

<button @onclick="() => { }">clickme</button>

@code {
    private Object myObject = new object();
}

Here, the Nested component is always re-rendered on the button click, even though it's only parameter Object never changes.

I've defined Nested as

<h3>
     (last render at @DateTime.Now.TimeOfDay)
</h3>

@code {
    [Parameter]
    public Object Object { get; set; }
}

to simply observe when it re-renders.

I've also tried defining a new type that overrides Equals, GetHashCode and implements IEquatable<T>, but the effect is the same.

React wouldn't consider reference-equal objects to be different for the purpose of re-rendering.

How can I pass non-primitive data to child components without marrying the child's re-rendering to that of the parent?

1

1 Answers

0
votes

You should call StateHasChanged() method whenever a property change may cause changes in UI.