Created
May 31, 2020 12:21
-
-
Save justinyoo/e6a99fffa35d032f70e937c7ccf14ddb to your computer and use it in GitHub Desktop.
Adding React UI Components to Blazor Web Assembly Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet new blazorwasm -n BlazorJsSample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script crossorigin src="//unpkg.com/react@16/umd/react.production.min.js"></script> | |
<script crossorigin src="//unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script> | |
<script crossorigin src="//unpkg.com/office-ui-fabric-react@7/dist/office-ui-fabric-react.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
window.RenderProgressBar = (count) => { | |
const Progress = () => React.createElement( | |
Fabric.ProgressIndicator, | |
{ | |
'label': 'React Counter', | |
'description': count, | |
'percentComplete': (count % 10) * 0.1 | |
}, | |
null | |
); | |
ReactDOM.render(Progress(), document.getElementById('reactProgressBar')); | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page "/counter" | |
@inject IJSRuntime Jsr | |
<h1>Counter</h1> | |
<p>Current count: @currentCount</p> | |
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button> | |
<div id="reactProgressBar"></div> | |
@code { | |
private int currentCount = 0; | |
private async void IncrementCount() | |
{ | |
currentCount++; | |
await Jsr.InvokeVoidAsync("RenderProgressBar", currentCount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment