Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Blazor is setting component parameter every time I interact with component

What I want to achieve is to call a function every time Parameter value of a component is updated, So I created a component with a Parameter and call a method inside its setter like this.

private LookupConfig _lookupConfig;

Parameter]
public LookupConfig Config { get { return _lookupConfig; } set { _lookupConfig = value; Console.WriteLine("Parameter Setter"); InitializeDropdownValues(); } }

In my parent component, I have a property.

public LookupConfig CustomerDropdown = new LookupConfig { LookupType = LookupType.Customer };

and I am passing it to child component like this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<NeeleezAutoComplete Config="CustomerDropdown"/>

but every time I interact with NeeleezAutoComplete component setter of Parameter property Config is get called.

is it intentional behaviour of blazor parameters am i missing something ? and how do i achieve this functionlaity?

>Solution :

is it intentional behaviour of blazor parameters

Yes, this is by design. Blazor tracks parameter changes very lightly.

The solution seems simple:

set 
{ 
  if (_lookupConfig == value) return;   // no change? Out of here. 
  _lookupConfig = value; 
  Console.WriteLine("Parameter Setter"); 
  InitializeDropdownValues(); 
}

You may want to check Equality for LookupConfig but normally the defaults should suffice.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading