Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

In blazor, variable current value is not maintained on component re-render

$
0
0

I have defined one variable named ActiveStep, like below:

[Parameter]public int ActiveStep { get; set; } = 0;

Below, I have shared my sample code.

<button class="e-btn" @onclick="Previous">Previous</button><button class="e-btn" @onclick="Next">Next</button><MyComponent @ref="_instance" ActiveStep="1"><ComponentItems><ComponentItem Label="Cart" IconCss="sf-icon-cart"></ComponentItem ><ComponentItem Label="Address" IconCss="sf-icon-user"></ComponentItem ><ComponentItem Label="Delivery" IconCss="sf-icon-transport"></ComponentItem ><ComponentItem Label="Payment" IconCss="sf-icon-payment"></ComponentItem ></ComponentItems></MyComponent >@code {    private MyComponent _instance { get; set; }    private async Task Next()    {        await _instance.NextStepAsync();    }    private async Task Previous()    {        await _instance.PreviousStepAsync();    }

In the above sample, initially the ActiveStep value is set to 1, and when I click the next button, the ActiveStep value is updated from 1 to 2, and then again, when I click the next button, the ActiveStep value should be updated from 2 to 3, but it is reset to the initial value of 1, and after it is updated to 3, each time I click the next or previous button or make any dynamic changes, it gets reset to the initial value of 1.

I have tried without setting the ActiveStep value initially, and it's working fine. The ActiveStep value reset issue only occurs when I set the ActiveStep value initially. I can't find the root cause.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>