Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Last active May 8, 2020 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/f4ad9315f896c312a50020978cefbc89 to your computer and use it in GitHub Desktop.
Save gavilanch/f4ad9315f896c312a50020978cefbc89 to your computer and use it in GitHub Desktop.
@page "/counter"
@inject IJSRuntime js
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button id="counterClick" class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await js.InvokeVoidAsync("initializeCounterComponent");
}
}
private void IncrementCount()
{
currentCount++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment