Counter.razor 785 B

123456789101112131415161718192021222324252627282930
  1. <p>Increment amount: @IncrementAmount</p>
  2. <p>Interactive: <span id="is-interactive-@IdSuffix">@_isInteractive</span></p>
  3. <p>Current count: <span id="count-@IdSuffix">@_currentCount</span></p>
  4. <button id="increment-@IdSuffix" @onclick="IncrementCount">Click me</button>
  5. @code {
  6. private int _currentCount = 0;
  7. private bool _isInteractive = false;
  8. [Parameter, EditorRequired]
  9. public int IncrementAmount { get; set; }
  10. [Parameter, EditorRequired]
  11. public string IdSuffix { get; set; }
  12. private void IncrementCount()
  13. {
  14. _currentCount += IncrementAmount;
  15. }
  16. protected override void OnAfterRender(bool firstRender)
  17. {
  18. if (firstRender)
  19. {
  20. _isInteractive = true;
  21. StateHasChanged();
  22. }
  23. }
  24. }